+ Start a Discussion
lovetolearnlovetolearn 

Trigger not firing

Hi, 

 

I am trying to update a field on a record after its been inserted using a trigger. For some reason, the trigger is not firing. Here is my code: 

trigger eventType on Party_Event__c (after insert, after update) {
    for(Party_Event__c pe : trigger.new){
        String events = pe.Type_of_Events__c;
        DateTime startDate = pe.start_date__c;
        DateTime endDate = pe.end_date__c;
        
        if(startDate == null){
            events = 'No Specific Date';
        }
        
    }
}

 

Please help. Thank you. 

AmitSahuAmitSahu

You need to update the record. ALso if you want the trigger to fire one insert why you have written after update ?

 

You can try this code ;

 

trigger eventType on Party_Event__c (after insert, after update) {
List<(Party_Event__c > lstP = new List<(Party_Event__c>();

for(Party_Event__c pe : trigger.new){
String events = pe.Type_of_Events__c;
DateTime startDate = pe.start_date__c;
DateTime endDate = pe.end_date__c;

if(startDate == null){
events = 'No Specific Date';
}
lstP.add(pe);
}

update lstP;
}

lovetolearnlovetolearn

Hi,

 

Thank you for your help. I got the "Cannot perform DML Statement on Trigger.new or Trigger.old..." error. It's okay though, I figured it out, I changed it from after update to before update. All set now.