Too many SOQL queries: 101
J
Written by James Kent
Updated over a week ago

⚠️ This is a technical article. You will need an intermediate technical knowledge of Salesforce. If you require assistance, we recommend forwarding this article to your Salesforce partner.

Overview

When working with Salesforce Nonprofit Success Pack (NPSP) and Salesforce in general, you must work within a set of limits for each transaction called Governor Limits. One of these limits is related to SOQL; a transaction can perform 100 queries in an execution. Regarding NPSP, these are typically consumed by triggers processing the creation or updating of records like contacts, campaigns, opportunities, etc.

Scenarios

In our experience, this issue can occur when there are:

  • a large number of Process Builder jobs or Lightning Flows that have been set to trigger off events on key records like opportunities; or

  • the NPSP has been in or before 2018 and there are a large number of legacy NPSP trigger handlers configured that need to be decommissioned

Solution

If you have a large number of Process Builder jobs or event-based Lightning Flows (other than the highly optimised ones from MoveData), then consider consolidating these into a smaller number. There is quite a performance penalty for each job so where they can be combined, we highly recommend it. If you still have a large number that cannot be consolidate, then we suggest you rework these into Apex triggers; a well-constructed trigger is much kinder to governor limits.

ℹ️ Trigger handlers are an abstracted version of Apex Triggers. They are managed using an NPSP custom object called npsp__Trigger_Handler__c.

If you have been running NPSP for a while, you might have a large number of legacy trigger handlers. As of NPSP version 3.181 with Affiliations, Relationships, Recurring Donations and Households installed, you should have 55 NPSP Triggers handler configured out of the box. In older installs, we have seen over 161 triggers configured. Culling no longer required triggers handler entries will typically provide SOQL limit relief.

If you haven’t added custom NPSP trigger handler entries, which 99% of customers will not have, then you should be able to execute a full delete on the object. Interestingly, it does appear to have a handler that will recreate the minimum entries (which is inline with a new NPSP installation) when the delete is executed.

⚠️ Take a backup of the data held within the npsp__Trigger_Handler__c object before completing the delete.

This can be completed by opening the Developer Console and executing delete [SELECT Id FROM npsp__Trigger_Handler__c];. Execute the following SOQL statement in the Query Editor to verify that the NPSP trigger handler entries have been recreated: SELECT COUNT(Id) FROM npsp__Trigger_Handler__c.

Requeue any failing notifications and see if the SOQL 101 issue have been addressed.

Did this answer your question?