Newer Version Available
EventRelation
EventRelation allows a variable number of relationships and handles deleted events differently, depending on whether Shared Activities is enabled.
- If Shared Activities Is Enabled
-
- An event can be related to up to 50 contacts or one lead.
- An event can be related to a lead, contact, resource, account, or opportunity.
- An event can be related to a custom object that has the HasActivities attribute set to true.
- If you delete an event, then relations between the event and any specified contacts, leads, and other records are also deleted.
- If you delete the EventRelation record representing a relation then the corresponding relation field may be cleared on the event.
- If you delete the EventRelation record representing the WhoId on an event, then another Who, if any, from the event’s EventWhoIds field will be promoted to the WhoId.
- If you restore a deleted event, relations between the event and any specified contacts, leads, and records are also restored. The WhoId, WhatId, and AccountId field values are recalculated using the field values on EventRelation.
- If Shared Activities Isn’t Enabled
-
- An event can be related to only one contact or lead, referenced in the event WhoId field. EventRelations will only be invitees (contacts, users, and resources).
- An event can also be related to one or more users or resources, represented in the EventWhoIds field on the event.
Whether or not Shared Activities is enabled, an event can be related to one other kind of record, such as an account, an opportunity, or a custom object.
Supported Calls
create(), delete(), describeSObjects(), getDeleted(), getUpdated(), query(), queryAll(), retrieve(), update(), upsert()
Fields
| Field | Details |
|---|---|
| AccountId |
|
| EventId |
|
| IsDeleted |
|
| IsInvitee |
|
| IsParent |
|
| IsWhat |
|
| RelationId |
|
| RespondedDate |
|
| Response |
|
| Status |
|
Usage
- Invitee related lists display slightly different content. In Salesforce1, the invitee
related list includes invitees only, whereas in the full site, it also includes
the event owner. To reproduce the full site functionality in Salesforce1, use the
following API queries.
If you use Shared Activities in your Salesforce org, use this query:
1SELECT RelationId FROM EventRelation WHERE isInvitee = true AND eventId='[Event_Id]'where Event_Id is the child event’s ID.
If you don’t use Shared Activities, use this query:
1SELECT RelationId FROM EventRelation WHERE eventId='[Event_Id]'These queries get the main event’s relations and display them for the given child event. To further filter the results, add a WHERE clause.
- Send email notifications
- To send email notifications for a given event, query EventRelation for the event, iterate through the list, examine the status, and send email notifications to every person who accepted the invitation.
- Determine what events a given invitee is attending
- To determine all the events that a particular person is attending during a given time period (for example, next week), you can have a client application query the Event object for a given date range, iterate through the results, and, for each event, query the EventRelation object to determine whether the particular person (RelationId) has accepted an invitation to that event.
- Create an invitee if Shared Activities is enabled (or during the process of enabling it or rolling back)
- If the invitee is already a contact or lead, update IsInvitee to true.
- If the invitee is not already a contact or lead, create an EventRelation object for the invitee with IsInvitee set to true.
- Create an invitee if Shared Activities is not enabled
- Create an EventRelation object for the invitee.
- Query relations to a contact or a lead
-
1List<EventRelation> whoRelations = [SELECT Id, Relation.Name FROM 2 EventRelation WHERE EventId = '00UD0000005zijD' AND isParent = true AND isWhat = false]; - Query invitee relations
-
1List<EventRelation> inviteeRelations = [SELECT Id, Relation.Name FROM 2 EventRelation WHERE EventId = '00UD0000005zijD' AND isInvitee = true]; - Update an invitee relation to a contact or lead invitee relation
-
1EventRelation er = [SELECT Id FROM EventRelation WHERE EventId = 2 '00UD0000005zijD' AND isInvitee = true and isParent = false LIMIT 1]; 3er.isParent = true; 4update er; - Update a contact or lead relation to a contact or lead invitee relation
-
1EventRelation er = [SELECT Id FROM EventRelation WHERE EventId = 2 '00UD0000005zijD' AND isParent = true and isInvitee = false LIMIT 1]; 3er.isInvitee = true; 4update er; - Insert a contact or lead relation
-
1EventRelation er = new EventRelation(EventId = '00UD0000005zijH', 2 RelationId = '003D000000Q8aeV', isParent = true, isInvitee = false); 3insert er; - Insert an invitee relation
-
If isParent, isWhat and IsInvitee are not set, and RelationId is a contact, lead, user, or calendar, IsInvitee defaults to true. This means if an EventRelation isn’t specifically inserted as a relation to a contact or lead, it’s treated as an Invitee relation by default.
1EventRelation er = new EventRelation(EventId = '00UD0000005zijH', 2 RelationId = '003D000000Q8adV'); 3insert er; - Reproduce invitee related list functionality in Salesforce1
- Invitee related lists display slightly different content in Salesforce1 and
the full site. In Salesforce1,
the invitee related list includes invitees only, whereas in the full site,
it also includes the event owner.
If you use Shared Activities in your Salesforce org, use the following query to reproduce the full site functionality in Salesforce1:
1SELECT RelationId FROM EventRelation WHERE isInvitee = true AND eventId='[Event_Id]'where Event_Id is the child event’s ID.
If you don’t use Shared Activities, use this query:
1SELECT RelationId FROM EventRelation WHERE eventId='[Event_Id]'These queries get the main event’s relations and display them for the given child event. To further filter the results, add a WHERE clause.