Skip to content

Instantly share code, notes, and snippets.

@lfreeland
Last active September 27, 2019 10:11
Show Gist options
  • Save lfreeland/8bada6219bc94e07a11f6aa2e4aa9d2c to your computer and use it in GitHub Desktop.
Save lfreeland/8bada6219bc94e07a11f6aa2e4aa9d2c to your computer and use it in GitHub Desktop.
List<Task> tasks =
[SELECT Id,
WhatId,
TypeOf What
WHEN Account THEN BillingState, BillingCity
END
FROM Task
WHERE WhatId In (SELECT Id
FROM Account)];
for (Task t : tasks) {
// Compiler won't allow this:
// String billingState = t.What.BillingState
// Have to indirectly access whatRecord using the get function
SObject whatRecord = t.What;
String billingState = (String) whatRecord.get('BillingState');
system.debug(' whatRecord.BillingState:' + billingState);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment