I need to create a child event isChild=true with apex. I need it in my test class. any suggestion.
Event ev1=new Event (OwnerId=u.Id, Subject= 'Appel', WhoId = whoCon.Id, StartDateTime = Datetime.now(), EndDateTime= Datetime.now()+1); insert ev1; EventRelation er = new EventRelation(); er.RelationId= u1.Id; insert er; er.EventId = ev1.Id; update er; System.debug('#### EVENT 1 ischild ' + ev1.isChild);
I still got ischild = false.
Any Idea?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
my understanding is you don’t need to explicitly create a child event..
If an invitee is added to an event a new event is created with invitee as the owner and the isChild flag is set to true.
Refer this previous discussion : How to identify parent of child events?
So after you create your actual Event and the EventRelation, there should be a child event created automatically.
you can query that back and use it in your test class
List<Event> childEvents = [select id,ischild from event where subject = 'Appel' and isChild = true];
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0