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

get whoids of task

I am trying to get whoids associated with task for one of my use case. There are multiple contacts linked with the task and I need all of those reference Ids of linked contacts. I have written after insert, update trigger on task object. The debug log gives me only one id of linked contact. even if SOQL also gives me only one record when I query SELECT WhoId from Task. 
Anyone knows how to get all reference Ids (whoIds) using Apex in case if a task has more than one contact linked. 
Thanks in advance. 
​- Sandip

Hi Sandip,

Can you post your query ,if you want all whoId from task then you need to query all task then needs to interate .Needs to collect all whoid in Set Id .Here on ething I want to tell WhoId relationship is with both Contacts and Lead .So you need to filter with Object prefix to collect only contact Ids from who id .

With the help of set of contact ids you can get all contact records related to Task .

Let m eknow if it helps !!
Thanks for prompt response Manoj.
I need whoIds for one task at a time, when they are inserting or updating.I know it has reference with both contacts and leads but I am doing for contacts only for now as it is pre-known because we are not using leads as this point of time. 
Thank you again. 
Phil MurrayPhil Murray
Better late than never, but for future reference you query the TaskRelation or TaskWhoRelation (a filtered view of TaskRelation) object. The RelationId is the Id of the Contact.