Trying to determine best scenarios for using AggregateResult

e.g. Versus using a for loop gathering totals with += or similar syntax.

  • 1
    I'm actually going to post something about this on my blog in the next 24 hours or so.
    – sfdcfox
    Mar 7, 2016 at 17:32
  • Awesome! looking forward to it, didn't find much existing content out there on the topic
    – nickforce
    Mar 7, 2016 at 17:44
  • @sfdcfox can you also include some best practices for using aggregateresults in batch apex? e.g. rowlimits and querylocator
    – nickforce
    Mar 11, 2016 at 21:19

1 Answer 1


Use AggregateResult when possible. It always performs at least as well as manual loops. The more rows you need to process, the more you'll save in CPU time.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.