How do you reduce the number of SOQL in a transaction?

  1. Never make any SOQL, DML operation inside the loop

  2. 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:

  1. Bulkify your Code

  2. Avoid SOQL Queries or DML statements inside FOR Loops

  3. Bulkify your Helper Methods

  4. Using Collections, Streamlining Queries, and Efficient For Loops

  5. Streamlining Multiple Triggers on the Same Object

  6. Use of the Limits Apex Methods to Avoid Hitting Governor Limits.

  7. Use batch apex if you are working for more than 50000 records.