Code more efficiently to avoid 'Apex CPU time limit exceeded'
What's counted
- All Apex code
- Library functions exposed in Apex
- Workflow execution
What's not counted
- Database operations, e.g. DML, SOQL
- SOSL
- HTTP callouts
Using Map based query
Map<id,account> aMap = new Map<id,account>([Select Id,Name from Account limit 50000]);
Explore if your business allows you to do the operation asynchronously
chance to make code execute in @future
Aggregate SOQL usage
using SUM,AVG aggregate functions at the database
Only take necessary data and run a loop
This is essential now to filter only specific data while doing a for on a list of records as too much looping will increase CPU time