You need to sign in to do that
Don't have an account?
Andrew DiBacco
Trigger Test Class Error
Hello All,
I'm writing test for a trigger, but when I create the test data, I cannot get any id values to pass to the required fields (highlighted) on my custom object. The test class will save, but fails when I run it, saying that the required fields are missing on the insert. Any ideas why it won't update these fields? Here is the Test Class:
I'm writing test for a trigger, but when I create the test data, I cannot get any id values to pass to the required fields (highlighted) on my custom object. The test class will save, but fails when I run it, saying that the required fields are missing on the insert. Any ideas why it won't update these fields? Here is the Test Class:
@isTest
private class UpdateOppIdTest{
static testMethod void testUpdateOppId(){
string s1;
List<ID> AccID = New List<ID>();
List<ID> OppID = new List<ID>();
List<ID> ImpId = new list<ID>();
List<ID> ImpOppId = new list<ID>();
List<ID> ImpAccID = new list<ID>();
date newclosedate = date.newinstance(2016,1,1);
Map<ID,ID> mOpptoAcc = new Map<ID,ID>();
Account[] AccountsToCreate = new Account[]{};
for(Integer x=0; x<200;x++){
s1 = string.valueof(x);
Account a = new Account(
name = 'test' + s1
);
AccountsToCreate.add(a);
AccID.add(a.id);
}
Opportunity[] OpportunitiesToCreate = new Opportunity[]{};
for(Integer x=0; x<200;x++){
s1 = string.valueof(x);
Opportunity o = new Opportunity(
name = 'test' + s1,
closedate = newclosedate,
AccountId = AccID[x],
stagename = 'Discovery'
);
OpportunitiesToCreate.add(o);
OppID.add(o.id);
mOpptoAcc.put(o.id, AccID[x]);
}
Implementation__c[] ImplementationsToCreate = new Implementation__c[]{};
for(Integer x=0; x<200;x++){
s1 = string.valueof(x);
Implementation__c i = new Implementation__c(
name = 'test' + s1,
//These are the required fiels
opportunity__c = OppID[x],
account__c = mOpptoAcc.get(OppId[x])
);
ImplementationsToCreate.add(i);
ImpID.add(i.id);
ImpOppID.add(i.opportunity__c);
ImpAccID.add(i.account__c);
}
Test.startTest();
//Code fails at the insert
Insert ImplementationsToCreate;
List<Opportunity> OppList = [SELECT id, name, implementation__C FROM Opportunity WHERE implementation__c IN :ImpId];
List<Implementation__c> ImpList = [SELECT id, name, account__c, opportunity__c From Implementation__c WHERE opportunity__c IN :OppID];
Test.stopTest();
}
}