I am writing a code which supposed to process a list of ActivityHistories
for any SObject which supports them (like Opportunity, Account, etc). And at that point it's impossible to know what is the exact SObject type.
Here is my problem. I can get ActivityHistories for a known SObject type, like this:
Opportunity opp = Database.query(
'SELECT (SELECT Id, Subject, Status, Priority, OwnerId, WhoId '
+ 'FROM ActivityHistories '
+ 'ORDER BY CreatedDate DESC '
+ 'LIMIT 10 OFFSET 0 ) '
+ 'FROM Opportunity '
+ 'WHERE Id = \'0061100000E8pC1\' '
+ 'LIMIT 1');
System.debug(opp.ActivityHistories);
But how to get the list of ActivityHistories
in the case below?
Id fid = '0061100000E8pC1';
SObject obj = Database.query(
'SELECT (SELECT Id, Subject, Status, Priority, OwnerId, WhoId '
+ 'FROM ActivityHistories '
+ 'ORDER BY CreatedDate DESC '
+ 'LIMIT 10 OFFSET 0 ) '
+ 'FROM ' + fid.getSobjectType().getDescribe().label
+ ' WHERE Id = \'' + fid
+ '\' LIMIT 1');
String.valueOf(fid.getSObjectType())
instead.