Tune transaction based limits
Transaction limits protect primarily memory, CPU, and database.
Memory protected by heap size limit.
CPU protected by timeout limit(10 seconds ). Mostly happen because of infinite loops/recursion .
Database protected by limits like the number of queries per transaction or the number of records you can save.
Other common process based limits for transaction
Message queue (MQ). You can create only a certain number of asynchronous jobs in a single transaction. For example limit of 10 future calls per batch.
Job creation. Asynchronous jobs can spawn only one more asynchronous job.
Email. Too many emails can brand you as a spammer. Number of user licenses multiplied by 1,000; maximum 1,000,000.
Solutions to Avoid Reaching Transaction Limits
Embrace asynchronous : Because higher limits for asynchronous processing.
Test your code : high volume and high complex code need more and more testing.
Aggregate queries : Query one and iterate again and again instead of new query.
Record collections : Bulkify your query using collection like Set/List/Map.
Monitor your system like increased record counts and user traffic cause your code to approach your limits.














