Too many SOQL queries: 101 Salesforce Exception

Too many SOQL queries: 101 Salesforce Exception

System.LimitException: Too many SOQL queries: 101 Salesforce Exception is thrown when more than 100 SOQL queries are executed in a single synchronous transaction. For Asynchronous, the limit is 200. This is SOQL Governor Limit in Salesforce.

If you use subqueries, then each parent-child relationship counts as an extra query. The subqueries limit is three times higher than the top level queries.

Sample Code:

List < Account > lstAcct = [
    SELECT Id,
    ( SELECT Id FROM Contacts ),
    ( SELECT Id FROM Cases ),
    ( SELECT Id FROM Opportunities )
    FROM Account
];

System.debug(
    'Number of SOQL Queries allowed is ' + Limits.getLimitQueries()
);

System.debug(
    'Number of SOQL Queries executed ' + Limits.getQueries()
);

System.debug(
    'Number of Aggregate SOQL Queries allowed is ' + Limits.getLimitAggregateQueries()
);

System.debug(
    'Number of Aggregate SOQL Queries executed ' + Limits.getAggregateQueries()
);

What other automations count towards SOQL Governor limit?

1. Flow Get Records elements

2. Flow Update Records or Delete Records elements that use filter conditions

3. Process Builders Update Records action uses one SOQL query

Too many SOQL queries 101 Salesfor...
Too many SOQL queries 101 Salesforce Exception

Leave a Reply