Last active
September 27, 2019 10:11
-
-
Save lfreeland/8bada6219bc94e07a11f6aa2e4aa9d2c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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