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
akshay desai 9akshay desai 9 

Is It possible to create a trigger on lightning calendar

Deepali KulshresthaDeepali Kulshrestha
Hi Akshay,
You can apply the trigger to an event and then associate that event to the calendar. Please go through the following sample codes as they may be helpful in solving your problem:
trigger SE_Request_Calendar_Trigger on SE_Request__c (after insert) {
     list<event> newEvents = new list<event>();
     
     string salesOpsCalendar = 'Ops Calendar';

     for (SE_Request__c seRequest : System.Trigger.new) {
         try {
             newEvents.add(new Event(
                 
                 //  How do I convert 'Ops Calendar' to an id that owns our shared calendar?                 
                 OwnerId = ???, 

                 ActivityDateTime = seRequest.Date_of_Requested_Demo__c,

                 DurationInMinutes = 60,

                 // Local or on-site
                 Location = seRequest.Type_of_Demo__c,

                 Subject = 'Give a demo of ' + Products_for_Demo__c + ' for ' + seRequest.Requester_Name__c
               )
              );
         }
         catch(Exception e){
             system.debug(e);
         }
     } 
     
     insert newEvents;
}
For adding the event to the calendar please go through the following code as it may be helpful to you:
https://help.salesforce.com/articleView?id=creating_an_event_in_a_public_or_resource_calendar.htm&type=5
https://help.salesforce.com/articleView?id=events_and_calendars.htm&type=5


I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha.