TransWikia.com

Find Parent Event of Child Event

Salesforce Asked by Abhinav Gupta on December 27, 2020

Problem Statement

Show a list of events on visualforce page, and give ability to respond as accept/reject/maybe.

Scenario:

  • 3 users are participating in an event.
  • Event is created by a user named “Ab Jindal” and he invites two other sfdc users i.e. “Ab Dev” and “Sm Dev”
  • Here is event data with parent event and eventrelations created for owner “Ab Jindal”
    Event table query
  • EventRelation table data for this event:
    EventRelation table data

From above screenshots, its clear that one needs Parent Event Id to update any EventRelation. Even if we try to hack and create a new EventRelation record via invited user i.e. “Ab Dev” or “Sm Dev”, it will fail. Here is sample failure code

EventRelation er = new EventRelation(
                           RelationId = UserInfo.getUserId()  ,  
                           EventId = '00U2000000VcrubEAB',
                           Status = 'Declined'
                     );

insert er;

Here is the error which comes on executing above code:

System.DmlException: Insert failed. First exception on row 0; first
error: INVALID_OPERATION, You cannot create an Event Relation with a
child event.: [EventId]

So, I wanted to know either of following two questions:

  • How we can get parent event id from a child event ?
  • Or, how to update child event with accept/decline/maybe info ?

Similar Questions

On researching found this post which is somewhat close to my challenge, but is not having correct resolution.

2 Answers

Event Relation records to be inserted always with status as "New" but, later it can be updated to "Accepted" or "Declined" .

Insert :

EventRelation er = new EventRelation( RelationId = UserInfo.getUserId() ,
EventId = '00U2000000VcrubEAB', Status = 'New' );

insert er;

Update :

Get event id from event object. Then query to Event Relation and get the id(event relation record id) ;

EventRelation er = new EventRelation( Id = "EventRelation rec id",
Status = 'Declined' );

update er;

Answered by Rajesh Kumar on December 27, 2020

To decline the status, you will have to perform update not insert. Eventid & Relationid is not required to accept or reject the event.

Answered by user11048 on December 27, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP