Events are being created in salesforce from some external application. I need to get the participants from them in a trigger.

I am looping over the newly inserted Events and then trying to query, but the below query doesnt return anything. Although if I try the query in workbench with a proper ID for an Event, I am getting the required EventRelation record.

List<EventRelation> myEventRelations = [SELECT ID, EventID, RelationID, Relation.Email FROM EventRelation WHERE eventId=: myEvent.Id];

Where myEvent is an iterator over Event records.


Event is the parent record for one or more EventRelation records. During the insert trigger event for any parent record, child objects are not yet available. Typically, you'd need to write your trigger on the child object.

Your current design is not going to work that way, however. From the EventRelation documentation:

EventRelation does not support triggers, workflow, or data validation rules.

So you can't write a child trigger. Instead, you may need to consider a scheduled Apex process. You'll need to think carefully about the architecture, however, as it's likely that the remote application is adding EventRelation records in multiple API calls (which are multiple transactions). Your code will need to be resilient against seeing partial, in-progress data.

  • Thanks David. Do we have the child objects available in an update event?
    – Ashish V
    Apr 3 '19 at 13:46
  • @AshishV Maybe. It's going to be dependent upon exactly what operations your remote application performs and in which order.
    – David Reed
    Apr 3 '19 at 13:55
  • ok, so the basic requirement is to get the participants email IDs/relation.email out of the events to check if the attendees are employee of my company or not. If not, event would be retained but if they are employees of my company the event should not be retained in the system, they would need to be deleted. So to take up an approach of a batch process here, i guess there can't be an optimal time when batch class should be scheduled. What do you think about that @David ?
    – Ashish V
    Apr 3 '19 at 15:44

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.