I am trying to test a trigger which works on Account Contact Relationship so I want to perform the following:
- Insert an account
- Insert a contact
- Insert an account contact relationship (my trigger performs some textual extraction to find out account and contact)
My trigger however generates an exception:
System.DmlException: Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, You can't associate a private contact with a company.: [ContactId]
This is the code that generates the exception:
Account account = new Account(Vat_Code__c = 'Examplevat' ,Name = 'Example company2');
insert(account);
Contact contact = new Contact(FirstName = 'John', LastName = 'Smith', Fiscal_Code__c = 'MyFiscalCode1');
insert(contact);
Test.startTest();
AccountContactRelation relation = new AccountContactRelation(SurrogateId__c = 'MyFiscalCode1_Examplevat_Owner');
insert(relation);
Test.stopTest();
Is it necessary to have a primary account connected to the company before I could have a secondary connection?