-
Never make any SOQL, DML operation inside the loop
-
Try loading most of the data into collections (Set, List, and Map), creating formulas and rollup-summaries for reducing the number of overall SOQL calls.
Below are some important points to prevent hitting the governor limits:
-
Bulkify your Code
-
Avoid SOQL Queries or DML statements inside FOR Loops
-
Bulkify your Helper Methods
-
Using Collections, Streamlining Queries, and Efficient For Loops
-
Streamlining Multiple Triggers on the Same Object
-
Use of the Limits Apex Methods to Avoid Hitting Governor Limits.
-
Use batch apex if you are working for more than 50000 records.