You need to sign in to do that
Don't have an account?
HelloSan
i need a test class for code coverage for below trigger when parent updated child is updated
trigger Update on Opportunity(afterupdate){
List<Service__c lstservice=new List<Service__c>();
Map<id,Opportunity> oppMap=new Map<Id,Opportunity>();
for(Opportunity opp:Trigger.new){
oppMap.put(opp.Id,opp);
}
if(Trigger.isUpdate){
for(Opportunity opp :Trigger.new){
oppMap.put(opp.Id,opp);
}
List<Service__c> serList=[SELECTService_Type__c,Service_location__c FROM Service__c WHEREopppID IN:oppMap.keySet()];
List<Service__c> serviceListToUpdate=newList<Service__c>();
for(Service__c ser:serList){
ser.Service_Type__c=oppMap.get(ser.Id).Service_Type__c;
ser.Service_location__c=oppMap.get(ser.Id).Service_location__c
serviceListToUpdate.add(ser);
}
if(serviceListToUpdate.size()>0){
try{
update serviceListToUpdate;
}catch(DmlException de){
System.debug(de);
}
}
List<Service__c lstservice=new List<Service__c>();
Map<id,Opportunity> oppMap=new Map<Id,Opportunity>();
for(Opportunity opp:Trigger.new){
oppMap.put(opp.Id,opp);
}
if(Trigger.isUpdate){
for(Opportunity opp :Trigger.new){
oppMap.put(opp.Id,opp);
}
List<Service__c> serList=[SELECTService_Type__c,Service_location__c FROM Service__c WHEREopppID IN:oppMap.keySet()];
List<Service__c> serviceListToUpdate=newList<Service__c>();
for(Service__c ser:serList){
ser.Service_Type__c=oppMap.get(ser.Id).Service_Type__c;
ser.Service_location__c=oppMap.get(ser.Id).Service_location__c
serviceListToUpdate.add(ser);
}
if(serviceListToUpdate.size()>0){
try{
update serviceListToUpdate;
}catch(DmlException de){
System.debug(de);
}
}
All Answers
To cover the above mentioned trigger code, please insert an opportunity record and update the same.
Here is the smaple code:
https://developer.salesforce.com/forums/ForumsMain?id=906F0000000AZWKIA4
Thanks,
Pratik
To cover this test class you need to simply create one Opportunity and then create Service__c record where opptId will be inserted oppt ID.
After this you can update the oppt and cover the code.