function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
steve456steve456 

Need help to create events on Calendar

How to create events on calendar for custom objects

 

How to add default invitees whenver an event is created

 

 

 

natty dreadnatty dread

Steve,

 

I was recently interested in doing something similar. Take a look at the code below.

 

I'm still working on a class to test this so when I have 100% coverage I will update.

 

trigger test_custom_calendar on Testable__c (after insert, after update) {
	//new list of events
	list<Event> ev = new list<Event>();
	
	
	for(Testable__c t : trigger.new){
		//if new record, populate these fields
		if(trigger.isInsert){
			Event e = new Event();
			
			e.StartDateTime = t.Start_Time__c;
			e.EndDateTime = t.End_Time__c;
			e.Agent__c = t.Agents__c;
			e.OwnerId = UserInfo.getUserId();
			e.WhatId = t.Id;
			e.default_invitee_one__c = 'Peter Tosh';
			e.default_invitee_two__c = 'Gregory Isaacs';
			//add new rows
			ev.add(e); 
		}
		//if parent is updated, delete original event and create new
		if(trigger.isUpdate){
			Event dead_events = [SELECT WhatId, StartDateTime, EndDateTime FROM Event WHERE WhatId IN : trigger.old];
			delete dead_events;
			
			Event e = new Event();
			e.StartDateTime = t.Start_Time__c;
			e.EndDateTime = t.End_Time__c;
			e.Agent__c = t.Agents__c;
			e.OwnerId = UserInfo.getUserId();
			e.WhatId = t.Id;
			e.default_invitee_one__c = 'Peter Tosh';
			e.default_invitee_two__c = 'Gregory Isaacs';
			//add new rows
			ev.add(e); 
		}
	} 
	//insert new list
	insert ev;
}

 

-Natty

steve456steve456

I got it.I deployed into production.I got llike 95% code coverage sending events on calendar to multiple people one  time

HGriffHGriff

Natty or Steve- I'm trying to do something similar and I think I can adapt your trigger code. Could you share your test class with us? Thanks- HGriff