I am trying to create a unit test in Financial Services Cloud that tests operations on Household Roles. The org uses Person Accounts. Whenever I try and insert an AccountContactRelation with the Person Account set as primary (FinServ__Primary__c = true), the insertion fails with the following error:
System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Can't choose a business as a primary group or primary member.: []
Here is my setup method. It creates an account with RecordType of 'Client Household'. Then it creates a Person Account. Finally, I attempt to relate the two accounts by inserting a record into AccountContactRelation.
@testSetup static void setup()
{
RecordType householdRecordType = [SELECT Id FROM RecordType WHERE (Name = 'Household') AND (SObjectType = 'Account')];
Account a = new Account(
Name = 'Test Household',
RecordType = householdRecordType
);
insert a;
RecordType personAccountRecordType = [SELECT Id FROM RecordType WHERE (Name = 'Person Account') AND (SObjectType = 'Account')];
Account pa = new Account(
FirstName = 'Test',
LastName = 'Person Account',
RecordType = personAccountRecordType,
FinServ__IndividualType__c = 'Individual'
);
insert pa;
// Need to get the PersonContactId for the Person Account
pa = [SELECT PersonContactId FROM Account WHERE Id = :pa.Id];
AccountContactRelation acr = new AccountContactRelation(
AccountId = a.Id,
ContactId = pa.PersonContactId,
IsActive = true,
FinServ__PrimaryGroup__c = true,
FinServ__Primary__c = true,
Roles = 'Client',
FinServ__Rollups__c = 'Tasks;Events;Financial Accounts'
);
insert acr;
}
addError()
. Have you checked your validation rules and unmanaged Apex?