Financial Service Cloud - Cannot test multi-household, unable to access protected custom setting in apex test context
Trailblazer Community

Financial Service Cloud - Cannot test multi-household, unable to access protected custom setting in apex test context

Financial Services Cloud

Last updated 2019-03-22 ·Reference W-4467961 ·Reported By 3 users

Fixed in version FinServ 212

Summary
Financial Service Cloud:
The following error may occur during the tests on multi-household:

“System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, We're enabling multiple relationship groups for contacts. Try again in a few minutes.: []”

Reason:
There is currently lack of visibility for protected custom settings.

Repro
On FSC installed developer org:

1. Create a new test class with the following contents:
@isTest
private class TestMultiHH {

@testSetup
private static void setup() {
FinServ__IndustriesAppConfig__c defaultSetting = new FinServ__IndustriesAppConfig__c(
SetupOwnerId = UserInfo.getOrganizationId(),
FinServ__AutoCreateInverseRole__c = false,
FinServ__MultipleRelationshipGroups__c = true
);
insert defaultSetting;

Account individual = new Account(
Name = 'Acc1',
RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Individual').getRecordTypeId()
);

Account hh1 = new Account(
Name = 'Acc2',
RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Household').getRecordTypeId()
);
Account hh2 = new Account(
Name = 'Acc3',
RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Household').getRecordTypeId()
);
insert new List<Account> {individual, hh1, hh2};
}


@isTest
private static void testMultiHHAssignment() {

Contact individual = [
SELECT Id, Name
FROM Contact
WHERE Account.Name = 'Acc1'
];
List<Account> households = [
SELECT Id, Name
FROM Account
WHERE RecordType.Name = 'Household'
ORDER BY Name ASC
];

insert new AccountContactRelation(
AccountId = households[0].Id,
ContactId = individual.Id,
IsActive = true,
FinServ__PrimaryGroup__c = false,
FinServ__Primary__c = false
);

insert new AccountContactRelation(
AccountId = households[1].Id,
ContactId = individual.Id,
IsActive = true,
FinServ__PrimaryGroup__c = false,
FinServ__Primary__c = false
);
}
}

2. Execute test.
*Note that the test will fail with “System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, We're enabling multiple relationship groups for contacts. Try again in a few minutes.: []”

Workaround
Modify test to make use of SeeAllData=true.

Any unreleased services, features, statuses, or dates referenced in this or other public statements are not currently available and may not be delivered on time or at all. Customers who purchase our services should make their purchase decisions based upon features that are currently available.