James Kent
Aug 17, 2020
NPSP & Too Many SOQL Queries: 101
devider

This is a technical article. You will need an intermediate technical knowledge of Salesforce. If you require assistance, we recommend contacting us or 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 related to SOQL is that a transaction can only perform 100 queries in an execution. In an NPSP context, these governor limits are typically consumed by triggers processing the creation or updating of records like contacts, campaigns, opportunities, accounts, etc.

Scenarios

In our experience, exceeding governor limits can typically occur where:

Solution

Process Builder Jobs or Lightning Flows

There can be a significant performance penalty associated with a large number of Process Builder Jobs and Lightning Flows. To solve this issue, consider combining and consolidating these into a smaller set where possible. If you find you have a large number which cannot be consolidated, then we suggest you rework these into Apex triggers which, when well constructed, are much kinder to governor limits.

Trigger Handlers

Trigger handlers are an abstracted version of Apex Triggers and are managed using an NPSP custom object called npsp__Trigger_Handler__c. If you have been running NPSP for a while, you might find you 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 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.

To do this, take a backup of the data held within the npsp__Trigger_Handler__c object before completing the delete. Then complete by:

Following this, open MoveData and requeue any failed notifications to assess if the SOQL 101 issues have been addressed.