1

I'm trying to create a unit test for a trigger on Financial Accounts within the Financial Service Cloud package. The code looks at the Household on the Financial Account and updates a custom field. It's a relatively simple trigger and is working fine while doing functional testing via the UI. The problem occurs when I try to replicate the same actions in unit tests. For some reason the FSC automations are not running and setting the Household account, which then prevents my trigger updates occurring.

Here's my setup method that creates the necessary test data for a Household (Group) Account and an Individual (Person) Account. It then links them together via the AccountContactRelation object. According to the documentation this is all that should be necessary in order for the FSC automations to link up Household:

@testSetup static void setupData() {
        // enable group record rollups
        FinServ__WealthAppConfig__c wealthAppConfig = new FinServ__WealthAppConfig__c();
        wealthAppConfig.FinServ__ReferrerScoreCalcEnabled__c = true;
        wealthAppConfig.FinServ__EnableGroupRecordRollups__c = true;
        wealthAppConfig.FinServ__EnableBusinessReferralsMade__c = true;
        wealthAppConfig.FinServ__EnableRollupSummary__c = true;
        wealthAppConfig.SetupOwnerId = UserInfo.getOrganizationId();
        insert wealthAppConfig;

        // create require data for household account
        User managingDirector = TestDataFactory.createUser('BranchManager', null);
        insert managingDirector;

        Branch__c branch = TestDataFactory.createBranch('Test Branch', managingDirector.Id);
        insert branch;

        Client_Service_Unit__c unit = TestDataFactory.createClientServiceUnit('Test Unit', branch.Id, managingDirector.Id, managingDirector.Id);
        insert unit;

        // create household account
        Account householdAccount = TestDataFactory.createHouseholdAccount('Test Household', unit.Id);
        insert householdAccount;

        // create primary owner
        Account primaryOwner = TestDataFactory.createPersonAccount('PersonTest', null);
        insert primaryOwner;

        String primaryOwnerContactId = [SELECT PersonContactId FROM Account WHERE Id=:primaryOwner.Id].PersonContactId;

        // create relationship for household account and primary owner
        AccountContactRelation acr = new AccountContactRelation();
        acr.AccountId = householdAccount.Id;
        acr.ContactId = primaryOwnerContactId;
        acr.Roles = 'Client';
        acr.FinServ__Rollups__c = 'Tasks;Events;Financial Accounts';
        acr.IsActive = true;
        acr.FinServ__Primary__c = true;
        acr.FinServ__PrimaryGroup__c = true;
        insert acr;
    }

Below is my test method which fails on the last assertion:

@isTest static void populateHouseholdAccountTest() {
        // retrieve household and primary owner accounts
        Account householdAccount = [SELECT Id FROM Account WHERE Name='Test Household' LIMIT 1];
        Account primaryOwner = [SELECT Id, Linked_Household_Account__c, IsLinkedToHousehold__c FROM Account WHERE LastName='PersonTest' LIMIT 1];

        Test.startTest();

        // create new financial account without a household relationship
        FinServ__FinancialAccount__c financialAccount = TestDataFactory.createFinancialAccount('Test Financial Account', null, primaryOwner.Id);
        insert financialAccount;

        Test.stopTest();

        // confirm the household relationship was set from the primary owner household
        FinServ__FinancialAccount__c updatedFinancialAccount = [SELECT Id, FinServ__PrimaryOwner__c, FinServ__Household__c FROM FinServ__FinancialAccount__c WHERE Id=:financialAccount.Id];
        System.assertEquals(primaryOwner.Id, updatedFinancialAccount.FinServ__PrimaryOwner__c);
        System.assertEquals(householdAccount.Id, updatedFinancialAccount.FinServ__Household__c);
    }

Any ideas on how to troubleshoot this or force the Household automation to properly run? I thought putting the code within Test.startTest() and Test.stopTest() would force the automations to fire, but for some reason the test is still failing.

1

I found the answer! The client I'm working with has Person Accounts enabled so I needed to add an additional custom setting configuration in order to get the automations to fire. I couldn't find this documented anywhere so I wanted to share the answer. The entire configuration is as follows :

// enable group record rollups
FinServ__WealthAppConfig__c wealthAppConfig = new FinServ__WealthAppConfig__c();
wealthAppConfig.FinServ__ReferrerScoreCalcEnabled__c = true;
wealthAppConfig.FinServ__EnableGroupRecordRollups__c = true;
wealthAppConfig.FinServ__EnableBusinessReferralsMade__c = true;
wealthAppConfig.FinServ__EnableRollupSummary__c = true;
wealthAppConfig.SetupOwnerId = UserInfo.getOrganizationId();
insert wealthAppConfig;

// add person account config
FinServ__UsePersonAccount__c personAccountConfig = new FinServ__UsePersonAccount__c();
personAccountConfig.Name = 'Use Person Account';
personAccountConfig.FinServ__Enable__c = true;
insert personAccountConfig;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.