0

hi all i have created an event with multiple contacts and then when i was trying to get the list contacts that are associated with an event in SOQL the result only first contact is returning i.e

Set<Id> contactIds = new Set<Id>();

for(Event e : [select subject,whoid from event where createdate = TODAY()])
{
  contactIds.Add(e.WhoID);
}

List<Contact> cons = [select Id, Name from Contact where ID IN : contactIds];
sytem.debug(cons)
1

That's by design - the WhoId always shows a single, primary relationship on the Event (or Task).

To get all associated contacts, you need to query the EventWhoRelation object, a junction between Event and Contact. You'd filter on EventId to get the relations for one or more specific Events.

Note however that EventWhoRelation doesn't necessarily point to a Contact (it could be a Lead, for example), but you can look at the Type field to tell the difference.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.