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
TomSnyderTomSnyder 

Maximum CPU time Exception Aggregation?

I have a trigger on the QuotelineItem that has some complex discount logic, it has been through mutiple iterations of optimization.  It will run well within gov limits when dealing with a batch of 200 records.   The problem is when we need to do Apex DML to all quotelineItems on a large quote (500+ items) using Apex.  (i.e. something like update [Select id from QuoteLineItem where id=:quoteid] ).  I get the Maximum CPU time exception.  
Since triggers run in there own transaction  I was under the assumtion that the trigger CPU time for the trigger would not be aggregated in the transaction where the Apex DML > 200 records is done,  but this does not seem to be the case.  

Can anyone shed some light on the accuracy of this aggregation and possible workarounds without using batch apex. 
NagaNaga (Salesforce Developers) 
Hi Tom,

Your trigger could take a very long time if allconts is a huge list of or allacc are really big!

You can use aggregate SOQL or “downwards” SOQL to make things a little simpler.

Aggregate SOQL: http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_SOQL_agg_fns.htm

Downwards SOQL:
http://www.sfdc99.com/2013/06/24/example-how-to-write-a-cross-object-soql-query-part-2/

Your trigger could take a very long time if allconts is a huge list of or allacc are really big!

You can use aggregate SOQL or “downwards” SOQL to make things a little simpler.

Aggregate SOQL: http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_SOQL_agg_fns.htm

Best Regards
Naga Kiran
 
TomSnyderTomSnyder
Naga, the Issue is related to gov limit aggregation as it relates to DML and triggers not SOQL aggregation.