SFDO-Community / declarative-lookup-rollup-summaries

Declarative Lookup Rollup Summaries (DLRS) is a community built and maintained Salesforce application that allows you to create cross object roll-ups declaratively - no code! For install instructions and documentation, visit our website https://sfdo-community-sprints.github.io/DLRS-Documentation/
https://sfdo-community-sprints.github.io/DLRS-Documentation/
BSD 3-Clause "New" or "Revised" License
690 stars 235 forks source link

NPSP Address Rollup Error #810

Open swift-ben opened 5 years ago

swift-ben commented 5 years ago

We have a rollup on the custom NPSP Address Object, rolling up to Accounts with a Record Type of Organization. Organization Addresses are only allowed if npspOrganizational_Account_Addresses_Enabledc field is checked in npe01Contacts_And_Orgs_Settingsc.

My dlrs_npsp_AddressTest class is failing with this error message:

System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, To use Addresses with non-Household Accounts, you must select Organizational Account Addresses Enabled in NPSP Settings | People | Addresses.: [] Class.dlrs.RollupService.testHandler: line 282, column 1 Class.dlrs_npsp_AddressTest.testTrigger: line 12, column 1

I've tried updating the custom setting before running the testHandler with no luck. Any advice would be appreciated.

danielbprobert commented 5 years ago

Can you share your test class, this will need a custom one.

2 options:

  1. Define custom settings in your test class to allow this behaviour in NPSP within your custom settings.
  2. Set test class to seealldata=true (ensures you can use your custom setting configuration in the org).

My preference would be 1 but both should work.

swift-ben commented 5 years ago

@danielbprobert see changes below. SeeAllData didn't work (ran into some dupe rule: _System.DmlException: Insert failed. First exception on row 0; first error: DUPLICATEVALUE, duplicate value found: SetupOwnerId duplicates value on record with id: 00D3C0000008tpF: [])

@IsTest private without sharing class dlrs_npsp_AddressTest { @IsTest private static void testTrigger() { insert new npe01Contacts_And_Orgs_Settingsc(npspOrganizational_Account_Addresses_Enabledc = true); // Force the dlrs_npsp_AddressTrigger to be invoked, fails the test if org config or other Apex code prevents this. dlrs.RollupService.testHandler(new npspAddressc()); } }

danielbprobert commented 5 years ago

You can't create the custom settings at the same time as with seealldata.

One or the other sorry I see the error in my message.

That error message is saying your custom settings are already there because you have seealldata enabled

swift-ben commented 5 years ago

Ah yeah, good call. I removed the setting and just used SeeAllData and I'm still getting the following error: To use Addresses with non-Household Accounts, you must select Organizational Account Addresses Enabled in NPSP Settings

danielbprobert commented 5 years ago

I know this might sound crazy but try removing your test class and then just run all test class. Pretty sure you'll get your coverage on the trigger. I have a vague memory of something similar to this with GAU Allocations

JimBTek commented 5 years ago

@swift-ben Have you set the NPSP custom setting in the UI to be True?

Also, if you are trying to run DLRS on all records, depending on what it is doing, it could be touching records and putting blanks in them, causing it to run on records that don't "fit" the validation rule.

What mode are you using?

Can you manually update the records in the way you are attempting to have DLRS update them? Can you limit your Select statement to avoid updating accounts that are the wrong Record Type? or perhaps use Process Builder instead to control only calling the rollup if the record type is Organization.

Just some guesses. It doesn't sound like a DLRS issue.

JTPropst commented 3 years ago

I am encountering the same error trying to set up DLRS for Addresses and Accounts in NPSP. Was a solution ever found? We currently do not have a workaround and I have minimal experience working with Apex Triggers and Apex Classes.

Mikeylightsit commented 3 years ago

Me too--on the NPSP Settings GUI I do have "Organizational Account Addresses Enabled" checked, but the trigger deployment is acting as if I don't. Has anyone else encountered this?

RealEvanPonter commented 3 years ago

I was able to successfully deploy the DLRS triggers for the NPSP Address object (npspAddressc) by putting this code in the "Test Code (Child Object)" field for my Lookup Rollup Summary configuration:

    Id recordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('HH_Account').getRecordTypeId();

    Account acc = new Account(
        Name = 'Test',
        RecordTypeId = recordTypeId
    );
    insert acc;

    // Force the dlrs_npsp_AddressTrigger to be invoked, fails the test if org config or other Apex code prevents this.
    dlrs.RollupService.testHandler(new npsp__Address__c(
        npsp__Household_Account__c = acc.Id
    ));

I'm hoping this is generic enough to work for others without any modification, but here's a few other tips if you still have trouble:

  1. If you have required fields on the Account object, specify those after the "RecordTypeId = recordTypeId" pairing. Be sure to separate pairings with a comma.
  2. If you have required fields on the Address object, specify those after the "npsp__Household_Account__c = acc.Id" pairing. Be sure to separate pairings with a comma.
shalletantony commented 3 years ago

I was able to successfully deploy the DLRS triggers for the NPSP Address object (npspAddressc) by putting this code in the "Test Code (Child Object)" field for my Lookup Rollup Summary configuration:

    Id recordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByDeveloperName().get('HH_Account').getRecordTypeId();

    Account acc = new Account(
        Name = 'Test',
        RecordTypeId = recordTypeId
    );
    insert acc;

    // Force the dlrs_npsp_AddressTrigger to be invoked, fails the test if org config or other Apex code prevents this.
    dlrs.RollupService.testHandler(new npsp__Address__c(
        npsp__Household_Account__c = acc.Id
    ));

I'm hoping this is generic enough to work for others without any modification, but here's a few other tips if you still have trouble:

  1. If you have required fields on the Account object, specify those after the "RecordTypeId = recordTypeId" pairing. Be sure to separate pairings with a comma.
  2. If you have required fields on the Address object, specify those after the "npsp__Household_Account__c = acc.Id" pairing. Be sure to separate pairings with a comma.

Hi I am facing same issue to get the code coverage due to same error. Can you please help me how to implement this on Test Class thank you Shallet

RealEvanPonter commented 3 years ago

Hi Shallet.

I pasted the above code into the "Test Code (Child Object)" field under the "Advanced" section of the Lookup Rollup Summary record

image

Then click "Save". Then click "Manage Child Trigger" - you will see a preview of the test class code with the above addition. Then click "Deploy".

If you are still having issues, please post the error messages you are receiving along with screenshots.

shalletantony commented 3 years ago

Hi Shallet.

I pasted the above code into the "Test Code (Child Object)" field under the "Advanced" section of the Lookup Rollup Summary record

image

Then click "Save". Then click "Manage Child Trigger" - you will see a preview of the test class code with the above addition. Then click "Deploy".

If you are still having issues, please post the error messages you are receiving along with screenshots.

Thank you so much

In my Apex code I am inserting address into ie. npspAddressc
But its throwing error as To use Addresses with non-Household Accounts, you must select Organizational Account Addresses Enabled in NPSP Settings

Thank you Shallet

shalletantony commented 3 years ago

I have used below code in Testclass but stll it gives same error ...

insert new npe01Contacts_And_Orgs_Settingsc(npspOrganizational_Account_Addresses_Enabledc = true,Name = 'Contacts And Orgs Settings (Organization)');

RealEvanPonter commented 3 years ago

Hi Shallet - I tried inserting the custom setting as well and was receiving the same error you are now seeing. The only way I got this to work was to ensure that a Household Account record was being used for the Address record being created in all apex scenarios. Are you able to refactor your test class to ensure that a Household account is inserted and specified on the new Address record?