function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rakesh K 60Rakesh K 60 

WhoId is returning null in SOQL and not shown in Apex

Hi,

I'm writing an Apex class to retrieve the Activity History and in the result there is No WhoId, but able to see WhatID. My Apex API Version is 49(Also tried with 48 resulting the same). Here is my Code.
 
Map<String, List<sObject>> finList = new Map<String, List<sObject>>();
Account acc = [SELECT Id, Name,
               (SELECT Id, Subject, ActivityDate, WhatId, What.Name, WhoId, Who.Name, ActivitySubType FROM OpenActivities order by ActivityDate desc)
              FROM Account WHERE Id = '0012x000004g9gSAAQ'];
finList.put('actCur', acc.OpenActivities);
System.debug(finList.get('actCur'));

When I run this, here is my Sample Output.

User-added image
When I tried the Same in QueryEditor, In the output, WhoId is Shown as null. (to be simple, I got rid of the unnecessary fields).

here is my SOQL
SELECT Id, (SELECT Id, WhatId, WhoId FROM OpenActivities order by ActivityDate desc) FROM Account WHERE Id = '0012x000004g9gSAAQ'
And here is the output.

User-added image
Finally, I ran the query on the object(Task in current case) with the ID that is returned by OpenActivities, To my Surprise I'm able to see the result there. Here is my final SOQL.
 
Select WhoId, Who.Name from Task where ID='00T2x000006jnJJEAY'

And here is my output.

User-added imageI'm a bit confused about where am I going wrong. I'm running as System Admin. Please let me know how can I fix this.

Thanks
AnudeepAnudeep (Salesforce Developers) 
Hi Rakesh, 

Can you try with the PrimaryWhoId field from OpenActivities

A similar question was posted here

Anudeep