+ Start a Discussion
JkkJkk 

Trigger now firing when i am controlling recusiveness

I am trying to populate Notes_Preview__c on Description for event.
However it is not populating.

trigger:

if(trigger.isAfter ){
            if(trigger.isInsert || trigger.isUpdate ){
            EventTriggerUtil.updateDescription(trigger.new);
            }

class:
private static boolean Hassent = false;
    public void updateDescription(List<Event> eventList){
        List<Event> eventtoupdate = new List<Event>();
        If(!HasSent){
        for(event e:eventList){
            Event eve =new Event(Id = e.Id);
            eve.Description=eve.Notes_Preview__c;
            eventtoupdate.add(eve);
            HasSent=true;
        }
        }
        if(eventtoupdate.size()>0){
            update eventtoupdate;
        }
    
        
    }
Test Company 13Test Company 13
since you are updating data on same object as trigger being fired , the trigger should be written on trigger.isBefore not trigger.isAfte.
so try as given below

trigger:
if(trigger.isBefore ){
            if(trigger.isInsert || trigger.isUpdate ){
            EventTriggerUtil.updateDescription(trigger.new);
            }


class:
private static boolean Hassent = false;
    public void updateDescription(List<Event> eventList){
        List<Event> eventtoupdate = new List<Event>();
        If(!HasSent){
        for(event e:eventList){
            Event eve =new Event(Id = e.Id);
            eve.Description=eve.Notes_Preview__c;
            eventtoupdate.add(eve);
            HasSent=true;
        }
        }
        // removing dml since before trigger will not need dml 
        /* if(eventtoupdate.size()>0){
            update eventtoupdate;
        } */
        
    }