You need to sign in to do that
Don't have an account?
Joel R
Issue changing Contact to Invitee on EventRelation
Hi Everyone,
I've spent quite a while trying to resolve my issue with no success so reaching out to the "brains trust".
I want to be able to update the Event's related contact (i.e. WhoId) to be an Invitee for the event when a custom "Send Invite to Contact" checkbox field is checked.
I have created an Event trigger (after insert, after update), so that when a new Event is created or an existing record is updated and the new field is true, the trigger looks for the related EventRelation records for the Event, for the WhoId (EventRelation.RelationId), and set the IsAttendee field to TRUE.
Below is the snippet of code in the Trigger:
I created a Test case that performs the following:
When the upsert occurs, I get the following error message from Salesforce "System.DmlException: Insert failed. First exception on row 0; first error: INVALID_FIELD_FOR_INSERT_UPDATE, When isInvitee is false, the invitee attributes Status, Response, and Responded Date may not be modified: []"
This is a very strange error message, which I haven't seen on the Internet before. Would someone be able to help?
Many thanks.
I've spent quite a while trying to resolve my issue with no success so reaching out to the "brains trust".
I want to be able to update the Event's related contact (i.e. WhoId) to be an Invitee for the event when a custom "Send Invite to Contact" checkbox field is checked.
I have created an Event trigger (after insert, after update), so that when a new Event is created or an existing record is updated and the new field is true, the trigger looks for the related EventRelation records for the Event, for the WhoId (EventRelation.RelationId), and set the IsAttendee field to TRUE.
Below is the snippet of code in the Trigger:
List <EventRelation> ers = [ SELECT Id, EventId, RelationId, IsParent, IsInvitee, Status FROM EventRelation WHERE EventId IN : evtsForCalInvites.keySet() ]; // event Id / contact id, EventRelation Map <string, EventRelation> ersMap = new Map <string, EventRelation>(); for (EventRelation er : ers) { ersMap.put((string)er.EventId + (string)er.RelationId, er); } List <EventRelation> ersToUpsert = new List <EventRelation> (); for (Event evt : evtsForCalInvites.values()) { EventRelation er = new EventRelation(); if (ersMap.containsKey((string)evt.Id + (string)evt.WhoId)) { System.debug('Existing EventRelation record found'); er = ersMap.get((string)evt.Id + (string)evt.WhoId); } else { System.debug('Creating new EventRelation record'); er.EventId = evt.Id; er.RelationId = evt.WhoId; } er.IsInvitee = true; ersToUpsert.add(er); } upsert ersToUpsert;
I created a Test case that performs the following:
- Create Contact
- Create Event with Contact as WhoId and set Send_Calendar_Invite_to_Contact__c = true to the code in the trigger fires.
When the upsert occurs, I get the following error message from Salesforce "System.DmlException: Insert failed. First exception on row 0; first error: INVALID_FIELD_FOR_INSERT_UPDATE, When isInvitee is false, the invitee attributes Status, Response, and Responded Date may not be modified: []"
This is a very strange error message, which I haven't seen on the Internet before. Would someone be able to help?
Many thanks.
Thanks for your reply. I'm not exactly sure what you mean. Are you saying that the SOQL query for EventRelation does not access the true EventRelation object?
The strange thing is that if I manually execute the following code in the Developer Console, the EventReletion record is created.
But when I do the same from the "after" trigger of the Event object, I get the error "System.DmlException: Insert failed. First exception on row 0; first error: INVALID_FIELD_FOR_INSERT_UPDATE, When isInvitee is false, the invitee attributes Status, Response, and Responded Date may not be modified: []"
Did you find any solution to this? We are also facing a similar kind of issue. Any suggestions would really help us.
Unfortunately not, the issue is still unresolved.
Hi Becky,
I haven't looked into this recently, but last time I exhaustively read up on similar issues, it looked like Salesforce doesn't support this in its implementation of EventRelation.
I ended up educating users, informing them that they also need to add the contact to the "Attendees" field when Events are created.
Hopefully that helps.
Please see the debug logs for this. Any flow(Process builder) must be trying to update the Event record at the same time. For my case, it was Activity chatter feed post.