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
Swati Atrey 8Swati Atrey 8 

Apex trigger on Lead, causing "Apex CPU time limit exceeded"

Hi Team,
I am getting error on bulk Lead import, "CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY:CheckLeadDNCR: System.LimitException: Apex CPU time limit exceeded:--".
I checked trigger CheckLeadDNCR, it is not inserting/updating any data its a normal if else and very short trigger. Then why this error is coming on this trigger
Siddharth ManiSiddharth Mani
It is possible that there might be an infinite loop in your trigger. If you post your code, it would be easier to debug.
Swati Atrey 8Swati Atrey 8
Thanks for your reply Siddharth!!
Code is very simple and curLead.ASG_Contact__c is NULL (not in CSV), so effectively this code do not process anything, still giving error

trigger CheckLeadDNCR on Lead (after insert, before update) {
  for(Lead curLead:trigger.new) {
    if(system.isFuture()) return;
        if (system.trigger.isInsert) {
            if (curLead.ASG_Contact__c != null) {
                DNCRConnectorWebserviceCallout.checkDNCR(curLead.Phone,curLead.ASG_Work_Phone_Number__c,curLead.MobilePhone,curLead.ASG_Home_Phone__c,curLead.Id,'Lead',1);                 
           
            }
        } else if (system.trigger.IsUpdate) {
          if(system.isFuture()) return;
          Lead prevLead = trigger.oldMap.get(curLead.Id);
            //if (curLead.ASG_Contact__c != null &&
            //  (curLead.Phone != prevLead.Phone || curLead.MobilePhone != prevLead.MobilePhone || curLead.ASG_Work_Phone_Number__c != prevLead.ASG_Work_Phone_Number__c ||
            //    curLead.ASG_Contact__c != prevLead.ASG_Contact__c)) {
            if (curLead.ASG_Contact__c != null){
                DNCRConnectorWebserviceCallout.checkDNCR(curLead.Phone,curLead.ASG_Work_Phone_Number__c,curLead.MobilePhone,curLead.ASG_Home_Phone__c,curLead.Id,'Lead',1);                 
            }
        }
    }
}
Abhijeet Anand 6Abhijeet Anand 6
Please post your code