how to avoid soql queries inside for loops?
When queries are placed inside a for loop, a query is executed on each iteration and governor limit is easily reached. Instead, move the SOQL query outside of the for loop and retrieve all the necessary data in a single query. of maximum 20 SOQL Queries.