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
DortegalizardoDortegalizardo 

Querying Invitees from an Event.

Hi,

 

Well Im trying to get all the invitees from all the events. Ive tried the following:

 

public List<List<ActivityHistory>> lista {get;set;}
public List<List<ActivityHistory>> getOpen()
{

lista = new List<List<ActivityHistory>>();
SObject[] accounts = [SELECT Name,
(Select Subject, WhoId,WhatId, ActivityDate, Status, Priority, OwnerId FROM ActivityHistories) From Account];
for(SObject o : accounts){
if(o.getSObjects('ActivityHistories') != null){
List<ActivityHistory> element = (List<ActivityHistory>) o.getSObjects('ActivityHistories');
if(element != null){
lista.add(element);
}
}

}

return lista;
}

I get all the events by account and to test it Ive added 3 invitees for one of the test events. And when I run the query I only get the first invitee and no the other two. How can I get all the invitees in all the events?

 

Thanks in advance

Best Answer chosen by Admin (Salesforce Developers) 
sfdcfoxsfdcfox

Try using EventRelations instead, then:

 

[select ...,(select ... from eventrelations) from event where accountid = :accountid]

Remember that accountId must be a string or ID that references the account you'd like to query (or change :accountId to whatever the ID of the account is in your code).

All Answers

sfdcfoxsfdcfox

You want this:

 

http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_eventattendee.htm

 

Namely, the query you're asking for is just the PRIMARY attendee of the event, not the actual attendees proper. You'll need a query like this:

 

[SELECT ..., (SELECT ... FROM EventAttendees) FROM EVENT Where AccountId = :accountId]

(Fill in the fields you desire from each to complete the query.)

DortegalizardoDortegalizardo

I tried this on dev console:

 

SELECT Id,AccountId, (SELECT Id,AccountId FROM EventAttendees) FROM EVENT Where AccountId = : accountId 

and got this as an error: Unknown error parsing query

sfdcfoxsfdcfox

Try using EventRelations instead, then:

 

[select ...,(select ... from eventrelations) from event where accountid = :accountid]

Remember that accountId must be a string or ID that references the account you'd like to query (or change :accountId to whatever the ID of the account is in your code).

This was selected as the best answer
DortegalizardoDortegalizardo

Thats the thing Im not looking only for the invitees from only one event or account, I need the invitees from every event.

sfdcfoxsfdcfox

You might run into certain governor limits when trying to non-selectively query events, but you can certainly try. There's nothing stopping you from querying EventRelations or EventAttendees (it might be a versioning thing). Just remember, you're limited to 50,000 records per transaction, though.