I want to create a event after my record have been approved, I have a checkbox checked when my record is approved so I can create my event, but the record will be locked !!!!
There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was:
"Apex trigger TRTimeOffAfterUpdate caused an unexpected exception, contact your administrator: TRTimeOffAfterUpdate: execution of AfterUpdate caused by: System.FinalException: Record is read-only: Trigger.TRTimeOffAfterUpdate: line 4, column 1".
trigger TRTimeOffAfterUpdate on Time_Off__c (after update) {
for (Time_Off__c toEvent : Trigger.new) {
if(toEvent.Is_approved__c=true){
// Event event = new Event
Event ev= new Event
(
OwnerId = toEvent.CreatedById,
StartDateTime = toEvent.Start_date__c,
EndDateTime = toEvent.End_date__c,
Subject = toEvent.Pattern__c,
Description = toEvent.Comment__c,
ShowAs = 'Out of Office'
);
insert ev ;
}
}