You need to sign in to do that
Don't have an account?
Test Class Question: Record Type ID not valid the for users profile: it is enabled for the profile
The test below tests a trigger that inserts a record for a custom object called 'Disbursement Destination' that has a Master-Detail relationship with Account and a LookUp relationship with Case. I think my error is coming when I insert the accounts for the test. I am getting the following message:
System.DmlException: Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, Record Type ID: id value not valid for the users profile: 012C0000000BqFyIAK: [RecordTypeId]
The record type is turned on for my profile.
The only clue that I've found is that sometimes in order to use a person account record type, you must have at least one Business record created. However, when I tried to create a business account record I got this error:
There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Business Relationship may not use Relationship field : Mailing Street".
I do not have any validation rule with that or a similar name.
Any thoughts on this?? This is my first attempt at writing a trigger/test and I am completely stumped. It is also my first post to the board, so please let me know if I did anything wrong or can provide any more information on this question. Thanks!
@isTest private class TestCreateNewDistributionDestination{ static testMethod void testUpdateCaseToCreateNew(){ ////Query RecordType Id to Create PersonAccounts for Test//// Id RecId = [ SELECT r.Id, r.Name, r.DeveloperName, r.IsPersonType FROM RecordType r WHERE sObjectType = 'Account' AND IsPersonType=True AND DeveloperName='Individual' ].Id; system.debug('RecordId:' + RecId); ////Create PersonAccounts for Test//// Account[] accs = new Account[]{ new Account(Salutation = 'Mr.', FirstName = 'John', LastName= 'Sandbox1', Relationship_Type__c = 'Current',BT_or_BGAM__c = 'Beacon Trust', RecordTypeId=RecId), new Account(Salutation = 'Mr.', FirstName = 'John', LastName= 'Sandbox2', Relationship_Type__c = 'Current',BT_or_BGAM__c = 'Beacon Trust', RecordTypeId=RecId) }; insert accs; system.debug('Accounts Have Been Created'); Map<String,Id> DDRTMap = new Map<String,Id>{}; ////Generate a List of Disbursement Destination Record Types//// List<RecordType> DDRTList = [ SELECT r.DeveloperName, r.Id, r.Name FROM RecordType r WHERE sObjectType = 'Disbursement_Destination__c']; ////Put the List into a Map//// for(RecordType RT: DDRTList){ DDRTMap.put(RT.DeveloperName,RT.Id); } system.debug('<<<<ABOUT TO INSERT CASES>>>>'); ////Create 6 Cases for the Test; 2 of each of 3 record types; 1 insert, 1 update of each//// Case[] Css = new Case[]{ new Case( Account = accs.get(0), Type = 'Wire Request', RecordTypeId = DDRTMap.get('Disbursement_Destination_Wire'), Existing_or_New_Disbursement_Destination__c = 'Use/Create a New Disbursement Destination', Receiving_Account_s_Number_Case__c = '135792468', Receiving_Account_s_Name_Case__c = 'TEST Receiving Account', Payee_s_Name_Case__c = accs.get(0).name, Payee_s_Street_Case__c = '1 Test Lane', Payee_s_City_Case__c = 'Testville', Payee_s_State_Case__c = 'NJ', Payee_s_Zip_Code_Case__c = '12345', Receiving_Bank_s_Name_Case__c = 'TEST BANK', Receiving_Bank_s_ABA_ACH_Case__c = '123456789', Receiving_Bank_s_ABA_Wire_Case__c= '123456789', Receiving_Bank_s_Street_Case__c = '1 Bank Street', Receiving_Bank_s_City_Case__c = 'Bankstown', Receiving_Bank_s_State_Case__c = 'NJ', Receiving_Bank_s_Zip_Code_Case__c = '98765' ), new Case( Account = accs.get(1), Type = 'Wire Request', RecordTypeId = DDRTMap.get('Disbursement_Destination_Wire'), Existing_or_New_Disbursement_Destination__c = 'Leave Disbursement Destination Blank', Receiving_Account_s_Number_Case__c = '135792468', Receiving_Account_s_Name_Case__c = 'TEST Receiving Account', Payee_s_Name_Case__c = accs.get(1).name, Payee_s_Street_Case__c = '1 Test Lane', Payee_s_City_Case__c = 'Testville', Payee_s_State_Case__c = 'NJ', Payee_s_Zip_Code_Case__c = '12345', Receiving_Bank_s_Name_Case__c = 'TEST BANK', Receiving_Bank_s_ABA_ACH_Case__c = '123456789', Receiving_Bank_s_ABA_Wire_Case__c= '123456789', Receiving_Bank_s_Street_Case__c = '1 Bank Street', Receiving_Bank_s_City_Case__c = 'Bankstown', Receiving_Bank_s_State_Case__c = 'NJ', Receiving_Bank_s_Zip_Code_Case__c = '98765' ), new Case( Account = accs.get(0), Type = 'Wire Request', RecordTypeId = DDRTMap.get('Disbursement_Destination_ACH'), Existing_or_New_Disbursement_Destination__c = 'Use/Create a New Disbursement Destination', Receiving_Account_s_Number_Case__c = '135792468', Receiving_Account_s_Name_Case__c = 'TEST Receiving Account', Payee_s_Name_Case__c = accs.get(0).name, Payee_s_Street_Case__c = '1 Test Lane', Payee_s_City_Case__c = 'Testville', Payee_s_State_Case__c = 'NJ', Payee_s_Zip_Code_Case__c = '12345', Receiving_Bank_s_Name_Case__c = 'TEST BANK', Receiving_Bank_s_ABA_ACH_Case__c = '123456789', Receiving_Bank_s_ABA_Wire_Case__c= '123456789', Receiving_Bank_s_Street_Case__c = '1 Bank Street', Receiving_Bank_s_City_Case__c = 'Bankstown', Receiving_Bank_s_State_Case__c = 'NJ', Receiving_Bank_s_Zip_Code_Case__c = '98765' ), new Case( Account = accs.get(1), Type = 'Wire Request', RecordTypeId = DDRTMap.get('Disbursement_Destination_ACH'), Existing_or_New_Disbursement_Destination__c = 'Leave Disbursement Destination Blank', Receiving_Account_s_Number_Case__c = '135792468', Receiving_Account_s_Name_Case__c = 'TEST Receiving Account', Payee_s_Name_Case__c = accs.get(1).name, Payee_s_Street_Case__c = '1 Test Lane', Payee_s_City_Case__c = 'Testville', Payee_s_State_Case__c = 'NJ', Payee_s_Zip_Code_Case__c = '12345', Receiving_Bank_s_Name_Case__c = 'TEST BANK', Receiving_Bank_s_ABA_ACH_Case__c = '123456789', Receiving_Bank_s_ABA_Wire_Case__c= '123456789', Receiving_Bank_s_Street_Case__c = '1 Bank Street', Receiving_Bank_s_City_Case__c = 'Bankstown', Receiving_Bank_s_State_Case__c = 'NJ', Receiving_Bank_s_Zip_Code_Case__c = '98765' ), new Case( Account = accs.get(0), Type = 'Wire Request', RecordTypeId = DDRTMap.get('Disbursement_Destination_Check'), Existing_or_New_Disbursement_Destination__c = 'Use/Create a New Disbursement Destination', Receiving_Account_s_Number_Case__c = '135792468', Receiving_Account_s_Name_Case__c = 'TEST Receiving Account', Payee_s_Name_Case__c = accs.get(0).name, Payee_s_Street_Case__c = '1 Test Lane', Payee_s_City_Case__c = 'Testville', Payee_s_State_Case__c = 'NJ', Payee_s_Zip_Code_Case__c = '12345', Receiving_Bank_s_Name_Case__c = 'TEST BANK', Receiving_Bank_s_ABA_ACH_Case__c = '123456789', Receiving_Bank_s_ABA_Wire_Case__c= '123456789', Receiving_Bank_s_Street_Case__c = '1 Bank Street', Receiving_Bank_s_City_Case__c = 'Bankstown', Receiving_Bank_s_State_Case__c = 'NJ', Receiving_Bank_s_Zip_Code_Case__c = '98765' ), new Case( Account = accs.get(1), Type = 'Wire Request', RecordTypeId = DDRTMap.get('Disbursement_Destination_Check'), Existing_or_New_Disbursement_Destination__c = 'Leave Disbursement Destination Blank', Receiving_Account_s_Number_Case__c = '135792468', Receiving_Account_s_Name_Case__c = 'TEST Receiving Account', Payee_s_Name_Case__c = accs.get(1).name, Payee_s_Street_Case__c = '1 Test Lane', Payee_s_City_Case__c = 'Testville', Payee_s_State_Case__c = 'NJ', Payee_s_Zip_Code_Case__c = '12345', Receiving_Bank_s_Name_Case__c = 'TEST BANK', Receiving_Bank_s_ABA_ACH_Case__c = '123456789', Receiving_Bank_s_ABA_Wire_Case__c= '123456789', Receiving_Bank_s_Street_Case__c = '1 Bank Street', Receiving_Bank_s_City_Case__c = 'Bankstown', Receiving_Bank_s_State_Case__c = 'NJ', Receiving_Bank_s_Zip_Code_Case__c = '98765' ) }; system.debug('Cases Have Been Created, But Not Inserted'); ////Insert the cases, update the cases needed test.starttest(); insert Css; system.debug('Inserted Css'); Css[1].Existing_or_New_Disbursement_Destination__c = 'Use/Create a New Disbursement Destination'; Css[3].Existing_or_New_Disbursement_Destination__c = 'Use/Create a New Disbursement Destination'; Css[5].Existing_or_New_Disbursement_Destination__c = 'Use/Create a New Disbursement Destination'; update Css; system.debug('Updated Css'); test.stoptest(); List<Case> insertedCases = [ SELECT Type, RecordTypeId FROM Case WHERE Id IN :Css]; system.debug(insertedCases.size() + ' Cases Have Been Created'); system.debug(insertedCases); System.AssertEquals(insertedCases.size(),6); for(Case Cs : insertedCases ){ System.AssertEquals('Disbursement Destination Already Populated',Cs.Existing_or_New_Disbursement_Destination__c); System.AssertNotEquals('',Cs.Disbursement_Destination__c); } List<Disbursement_Destination__c> TestDDs = [ SELECT name FROM Disbursement_Destination__c]; system.debug(TestDDs); } }
}
}
Try the following:
At this point, you will have "married" the account to the contact, thus converting the business accounts to person accounts.
Thanks, I've made the change, but I now get this error.
I am now getting this error:
System.DmlException: Insert failed. First exception on row 0; first error: INVALID_FIELD_FOR_INSERT_UPDATE, Business Relationship may not use Relationship field : Mailing Street: [Mailing Street]
Updated Code:
Hey, thanks again for the response. Any insight on the question that I posted below?
Thanks
Thanks for the help, I've made the change, but I now get this error:
System.DmlException: Insert failed. First exception on row 0; first error: INVALID_FIELD_FOR_INSERT_UPDATE, Business Relationship may not use Relationship field : Mailing Street: [Mailing Street]
Class.TestCreateNewDistributionDestination.testUpdateCaseToCreateNew: line 24, column 1
Any idea what is causing this and/or how to approach fixing it?
Thanks again!