We have NPSP installed as a managed package in our org and we have Automatic Affiliation Management turned off. I'm trying to test a trigger I've written on the Affiliation object (npe5__Affiliation__c) but I can't find a way to get test classes to respect this setting. For example, this test class fails:

    npe5__Affiliations_Settings__c affiliationsSettings = new npe5__Affiliations_Settings__c(
            npe5__Automatic_Affiliation_Creation_Turned_On__c = false,
            Name='Affiliations Settings (Organization)'

    insert affiliationsSettings;
    Account acct = new Account(
            Name = 'Test Organisation'
    insert acct;

    Contact cont = new Contact(
            FirstName = 'Test',
            LastName = 'Contact',
            Email = '[email protected]',
            AccountId = acct.Id
    insert cont;

    List<npe5__Affiliation__c> affiliations = [
            SELECT Id
            FROM npe5__Affiliation__c
            WHERE npe5__Contact__c = :cont.Id
    System.assertEquals(0, affiliations.size()); //Assertion Failed: Expected: 0, Actual: 1

Does anyone know how to resolve this?

1 Answer 1


Unfortunately, as of Jan 2021, NPSP still forces default settings in a test context and ignores any changes you make. See this open issue:

current settings facade always constructs new default custom settings if we are in a test execution context

At best, if your tests provide enough coverage, you can skip any asserts and just deploy. At worst, you'll have to try workarounds with additional test code.

BTW - the best resource for NPSP support is the Power of Us Hub. There are many discussion groups available including one for developers.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .