+ Start a Discussion
ChickenOrBeefChickenOrBeef 

Only some of my CPU Limit debug logs are showing up

Hey everyone,

I've run into the incredibly frustrating "Apex CPU time limit exceeded" error, so I put in debug statements throughout my triggers, in between each class call, which should show the CPU time after each class is called. That should theoretically tell me which class is causing the issue.

The problem is that only some of the debug logs show up.

For example, here is my main opportunity trigger, where all the opportunity classes are called. I have a debug statement after each call:
 
trigger MainTriggerOpportunity on Opportunity (before insert, before update, after insert, after update) {
    
    if(trigger.isBefore){
            
        if(trigger.isInsert){
            
            if(checkRecursive.runBeforeInsertOnce()){
            
            ClassOppIndustry updater = new ClassOppIndustry();
            updater.updateOppIndustry(Trigger.new);
                
               	System.debug(LoggingLevel.ERROR,'[OPP] BEFORE INSERT: CPU time after ClassOppIndustry is ' + Limits.getCpuTime() + '/' + Limits.getLimitCpuTime());
            
            ClassRenewalDate updater1 = new ClassRenewalDate();
            updater1.updateRenewalDate(Trigger.new);
                
                System.debug(LoggingLevel.ERROR,'[OPP] BEFORE INSERT: CPU time after ClassRenewalDate is ' + Limits.getCpuTime() + '/' + Limits.getLimitCpuTime());
                
            ClassLeadConvertUpdates updater2 = new ClassLeadConvertUpdates();
            updater2.updateLeadConvertFields(Trigger.new);
                
                System.debug(LoggingLevel.ERROR,'[OPP] BEFORE INSERT: CPU time after ClassLeadConvertUpdates is ' + Limits.getCpuTime() + '/' + Limits.getLimitCpuTime());
                
            }
            
        }
        if(trigger.isUpdate){
            
            if(checkRecursive.runBeforeUpdateOnce()){
            
            ClassOppIndustry updater = new ClassOppIndustry();
            updater.updateOppIndustry(Trigger.new);
                
                System.debug(LoggingLevel.ERROR,'[OPP] BEFORE UPDATE: CPU time after ClassOppIndustry is ' + Limits.getCpuTime() + '/' + Limits.getLimitCpuTime());
            
            ClassRenewalDate updater1 = new ClassRenewalDate();
            updater1.updateRenewalDate(Trigger.new);
                
                System.debug(LoggingLevel.ERROR,'[OPP] BEFORE UPDATE: CPU time after ClassRenewalDate is ' + Limits.getCpuTime() + '/' + Limits.getLimitCpuTime());
                
            ClassBrandParent updater2 = new ClassBrandParent();
            updater2.addBrandParent(Trigger.new);
                
                System.debug(LoggingLevel.ERROR,'[OPP] BEFORE UPDATE: CPU time after ClassBrandParent is ' + Limits.getCpuTime() + '/' + Limits.getLimitCpuTime());
                
            ClassCallScheduledAdvance updater3 = new ClassCallScheduledAdvance();
            updater3.addCallScheduledDate(Trigger.new,Trigger.oldMap);
                
                System.debug(LoggingLevel.ERROR,'[OPP] BEFORE UPDATE: CPU time after ClassCallScheduledAdvance is ' + Limits.getCpuTime() + '/' + Limits.getLimitCpuTime());
                
            }
     }
  }
    
    
    if(trigger.isAfter){
        
        if(trigger.isInsert){
            
            if(checkRecursive.runAfterInsertOnce()){
            
            ClassRenewalProcess updater = new ClassRenewalProcess();
            updater.updateRenewalStatus(Trigger.new);
                
                System.debug(LoggingLevel.ERROR,'[OPP] AFTER INSERT: CPU time after ClassRenewalProcess is ' + Limits.getCpuTime() + '/' + Limits.getLimitCpuTime());
            
            ClassOppBrandCreate updater1 = new ClassOppBrandCreate();
            updater1.addBrand(Trigger.new);
                
                System.debug(LoggingLevel.ERROR,'[OPP] AFTER INSERT: CPU time after ClassOppBrandCreate is ' + Limits.getCpuTime() + '/' + Limits.getLimitCpuTime());
                
            ClassOppTeamMember updater2 = new ClassOppTeamMember();
            updater2.insertOpp(Trigger.new);
                
                System.debug(LoggingLevel.ERROR,'[OPP] AFTER INSERT: CPU time after ClassOppTeamMember is ' + Limits.getCpuTime() + '/' + Limits.getLimitCpuTime());
                
            ClassPrimaryContactCopy updater4 = new ClassPrimaryContactCopy();
            updater4.copyPrimary(Trigger.new);
                
                System.debug(LoggingLevel.ERROR,'[OPP] AFTER INSERT: CPU time after ClassPrimaryContactCopy is ' + Limits.getCpuTime() + '/' + Limits.getLimitCpuTime());
                
            ClassOppPicklists updater5 = new ClassOppPicklists();
            updater5.updatePicklists(Trigger.new);
                
                System.debug(LoggingLevel.ERROR,'[OPP] AFTER INSERT: CPU time after ClassOppPicklists is ' + Limits.getCpuTime() + '/' + Limits.getLimitCpuTime());
                
            ClassBDSourceCreate updater6 = new ClassBDSourceCreate();
            updater6.addBDSource(Trigger.new);
                
                System.debug(LoggingLevel.ERROR,'[OPP] AFTER INSERT: CPU time after ClassBDSourceCreate is ' + Limits.getCpuTime() + '/' + Limits.getLimitCpuTime());
                
            ClassMapPlatform updater7 = new ClassMapPlatform();
            updater7.copyPlatform(Trigger.new);
                
                System.debug(LoggingLevel.ERROR,'[OPP] AFTER INSERT: CPU time after ClassMapPlatform is ' + Limits.getCpuTime() + '/' + Limits.getLimitCpuTime());
                
            ClassAnnualDealRevenue updater8 = new ClassAnnualDealRevenue();
            updater8.addAnnualRevenue(Trigger.new);
                
                System.debug(LoggingLevel.ERROR,'[OPP] AFTER INSERT: CPU time after ClassAnnualDealRevenue is ' + Limits.getCpuTime() + '/' + Limits.getLimitCpuTime());
                
            ClassDemandGenOpportunity updater9 = new ClassDemandGenOpportunity();
            updater9.addContactRoles(Trigger.new);
                
                System.debug(LoggingLevel.ERROR,'[OPP] AFTER INSERT: CPU time after ClassDemandGenOpportunity is ' + Limits.getCpuTime() + '/' + Limits.getLimitCpuTime());
                
            }
       }
        if(trigger.isUpdate){
            
            if(checkRecursive.runAfterUpdateOnce()){
            
            ClassRenewalProcess updater = new ClassRenewalProcess();
            updater.updateRenewalStatus(Trigger.new);
                
                System.debug(LoggingLevel.ERROR,'[OPP] AFTER UPDATE: CPU time after ClassRenewalProcess is ' + Limits.getCpuTime() + '/' + Limits.getLimitCpuTime());
            
            ClassOppBrandCreate updater1 = new ClassOppBrandCreate();
            updater1.addBrand(Trigger.new);
                
                System.debug(LoggingLevel.ERROR,'[OPP] AFTER UPDATE: CPU time after ClassOppBrandCreate is ' + Limits.getCpuTime() + '/' + Limits.getLimitCpuTime());
                
            ClassDrawLoopUpdates updater3 = new ClassDrawLoopUpdates();
            updater3.updateDrawLoopFields(Trigger.new);
                
                System.debug(LoggingLevel.ERROR,'[OPP] AFTER UPDATE: CPU time after ClassDrawLoopUpdates is ' + Limits.getCpuTime() + '/' + Limits.getLimitCpuTime());
                
            ClassPrimaryContactCopy updater4 = new ClassPrimaryContactCopy();
            updater4.copyPrimary(Trigger.new);
                
                System.debug(LoggingLevel.ERROR,'[OPP] AFTER UPDATE: CPU time after ClassPrimaryContactCopy is ' + Limits.getCpuTime() + '/' + Limits.getLimitCpuTime());
                
            ClassOppPicklists updater5 = new ClassOppPicklists();
            updater5.updatePicklists(Trigger.new);
                
                System.debug(LoggingLevel.ERROR,'[OPP] AFTER UPDATE: CPU time after ClassOppPicklists is ' + Limits.getCpuTime() + '/' + Limits.getLimitCpuTime());
                
            ClassBDSourceCreate updater6 = new ClassBDSourceCreate();
            updater6.addBDSource(Trigger.new);
                
                System.debug(LoggingLevel.ERROR,'[OPP] AFTER UPDATE: CPU time after ClassBDSourceCreate is ' + Limits.getCpuTime() + '/' + Limits.getLimitCpuTime());
                
            ClassMapPlatform updater7 = new ClassMapPlatform();
            updater7.copyPlatform(Trigger.new);
                
                System.debug(LoggingLevel.ERROR,'[OPP] AFTER UPDATE: CPU time after ClassMapPlatform is ' + Limits.getCpuTime() + '/' + Limits.getLimitCpuTime());
                
            ClassAnnualDealRevenue updater8 = new ClassAnnualDealRevenue();
            updater8.addAnnualRevenue(Trigger.new);
                
                System.debug(LoggingLevel.ERROR,'[OPP] AFTER UPDATE: CPU time after ClassAnnualDealRevenue is ' + Limits.getCpuTime() + '/' + Limits.getLimitCpuTime());
                
            ClassDemandGenOpportunityUpdate updater9 = new ClassDemandGenOpportunityUpdate();
            updater9.addContactRoles(Trigger.new,Trigger.oldMap);
                
       

                
            }
        }
    }
}

But here is the log after I mass updated some opportunities in production:

User-added image

As you can see, only the final debug statements are showing up. Any idea why that would be? Also, if you have any suggestions on how to better find out where the CPU limit error is coming from, that would be extremely appreciated.

Thanks!
-Greg
Cloud_forceCloud_force
i think there is a limit on logs that are seen. CPU time limit error comes when your transaction takes that much time. So it is the overall time taken for execution and not any specific statement that is failing for you. You should probably check for long running Queies or DML's that are taking long time. You can check time taken in logs (left hand side of the logs you can see time)

http://www.forcexplore.com/2014/08/visualforce-and-apex-tutorial-for-beginners.html