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
Arun Sarvan SamArun Sarvan Sam 

Apex CPU time limit exceed - Trigger

Hi frnds,

It shows alert like the below, could you please clarify anything went wrong in my trigger,

Please find error details below...
CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY - RichText1: System.LimitException: Apex CPU time limit exceeded
 
trigger RichText1 on CampaignMember (before insert, before update) {
    Set<Id> camIdSet=new Set<Id>();
      for(CampaignMember camm: Trigger.new){
       camIdSet.add(camm.CampaignId);
               system.debug('got camIdset');

     }
     Map<Id,Campaign> camMap=new Map<Id,Campaign>([SELECT Id,Extra_Info_for_Reminder__c FROM Campaign WHERE Id IN :camIdSet]);
     
     for(CampaignMember campMem: Trigger.new){
        system.debug('checkCamId: ' + campMem.campaignid);
         
       if(campMem.CampaignId != null ){
         campMem.Course_Email_Info_2__c=camMap.get(campMem.CampaignId).Extra_Info_for_Reminder__c;
         system.debug('checkCourse_email_info_2__c: '  + campMem.Course_Email_Info_2__c);

       }
     }
}

 
Ajay K DubediAjay K Dubedi
Hi Arun,
You need to follow some best practices of the apex.
Here is an article from Salesforce on how you can address this Apex CPU time limit exceeded error with best practices: https://help.salesforce.com/apex/HTViewSolution?id=000232681&language=en_US

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