I keep getting this error when running a Test Class and I just don't know where to go from here. I've tried disabling Parrallel Apex Testing, running the code as a standard user, etc. I must be missing something and I hope that someone can look it over and see where I went wrong. I would really appreciate any help.
For background information, I work at a non-profit so we are using the latest NPSP.
This is the error message:
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, npsp.TDTM_Contact: execution of BeforeInsert
caused by: System.AssertException: Assertion Failed: Expected: null, Actual: Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, Record Type ID: this ID value isn't valid for the user: 012j0000000KvvPAAS: [RecordTypeId]
(npsp)
: []
And here's the Test Class
@isTest
public class Test_FillOtherAddress {
static testMethod void insertContact() {
//Add one contact to create household
Contact con = new Contact(FirstName='TEST_FIRSTNAME', LastName='TEST_LASTNAME');
test.startTest();
insert con;
string addressType = 'Work';
string street = '123 Wooddale Ave';
string state = 'DE';
string postalCode = '1234567';
string country = 'USA';
//string householdRecordType='012j0000000AI7Q';
npsp__Address__c add = new npsp__Address__c(
//RecordTypeId = householdRecordType,
npsp__Household_Account__c=con.AccountId,
npsp__Address_Type__c = addressType,
npsp__MailingStreet__c = street,
npsp__MailingState__c =state,
npsp__MailingPostalCode__c = postalCode,
npsp__MailingCountry__c = country
);
insert add;
//Add another contact to test insert event trigger
Contact con2 = new Contact(FirstName='TEST_FIRSTNAME2', LastName='TEST_LASTNAME', AccountId=con.AccountId, Other_Address_Lookup__c=add.Id);
insert con2;
test.stopTest();
Contact insertedContact = [SELECT OtherStreet FROM Contact WHERE Id = :con2.Id];
System.assertEquals(street, insertedContact.OtherStreet);
}
}
My Trigger works fine, as far as I know:
trigger FillOtherAddress on Contact (before insert, before update) {
for(Contact c : Trigger.new){
if(c.Other_Address_Lookup__c !=null){
npsp__Address__c otherAddress =
[select npsp__Address_Type__c, npsp__Formula_MailingStreetAddress__c, npsp__MailingCity__c, npsp__MailingState__c, npsp__MailingPostalCode__c, npsp__MailingCountry__c
from npsp__Address__c where ID=:c.Other_Address_Lookup__c LIMIT 1];
c.npe01__Secondary_Address_Type__c = otherAddress.npsp__Address_Type__c;
c.OtherStreet = otherAddress.npsp__Formula_MailingStreetAddress__c;
c.OtherCity = otherAddress.npsp__MailingCity__c;
c.OtherState = otherAddress.npsp__MailingState__c;
c.OtherPostalCode = otherAddress.npsp__MailingPostalCode__c;
c.OtherCountry = otherAddress.npsp__MailingCountry__c;
}
}
}
Best Answer
I found on the PowerofUS hub an answer for this. Settings > Account > Record Types. Individual Type was disabled. When I enabled this, the error no longer happens.