You need to sign in to do that
Don't have an account?
gopal neeluru
How to write test class for below apex Trigger
trigger Example123 on Case (before insert, before update) {
Set<Id> accountIdSet = new Set<Id>();
for(Case caseForVarRecord : Trigger.new){
if(caseForVarRecord.AccountId != null ){
accountIdSet .add(caseForVarRecord.AccountId);
}
}
map<Id,Account> accountMap = new Map<Id,Account>([Select Id, Ownerid from Account where Id =: accountIdSet ]);
for (Case c: Trigger.new){
if(c.AdditionalCon__c ==null ){
c.AdditionalCon__c = accountMap.get(c.AccountId).OwnerId;
}
}
}
Set<Id> accountIdSet = new Set<Id>();
for(Case caseForVarRecord : Trigger.new){
if(caseForVarRecord.AccountId != null ){
accountIdSet .add(caseForVarRecord.AccountId);
}
}
map<Id,Account> accountMap = new Map<Id,Account>([Select Id, Ownerid from Account where Id =: accountIdSet ]);
for (Case c: Trigger.new){
if(c.AdditionalCon__c ==null ){
c.AdditionalCon__c = accountMap.get(c.AccountId).OwnerId;
}
}
}
try this test code
@istest private class case_test{
static testmethod void methodenames(){
case cse=new case();
cse.Origin='test';
cse.Status='testes';
cse.AdditionalCon__c ='test';
insert cse;
cse.Origin='test';
cse.Status='testes';
cse.AdditionalCon__c ='test';
update cse;
Account acc=new Account();
acc.name='test';
insert acc;
acc.name='test';
update acc;
}
}