以下のテストでは、取引先とのマスター/詳細関係とケースとのルックアップ関係を持つ「支払い先」というカスタム オブジェクトのレコードを挿入するトリガーをテストします。私の組織は (残念ながら) 個人取引先を使用していることに注意してください。
このエラーが発生しています:
System.DmlException: 挿入に失敗しました。行 0 の最初の例外。最初のエラー: INVALID_FIELD_FOR_INSERT_UPDATE、ビジネス関係は関係フィールドを使用できない可能性があります: 郵送先: [郵送先]
実行しようとしているコードは次のとおりです。
@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(Name='Mr. John Sandbox1'),
new account(name='Mr. John Sandbox2')
};
insert accs;
contact[] cons = new contact[] {
new contact(accountid=accs[0].id,salutation='Mr.',firstname='John',lastname='Sandbox1'),
new contact(accountid=accs[1].id,salutation='Mr.',firstname='John',lastname='Sandbox2')
};
insert cons;
accs[0].recordtypeid = accs[1].recordtypeid = RecId;
update 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);
//System.Assert(TestDDs.size(),2);
}
}