You need to sign in to do that
Don't have an account?
kROOM
I dont know how to write a test class for this one. I hope this will be answered since I am new here in Salesforce. Thank you.
public class OpportunityTriggerHandler {
public static void onBeforeInsert(List<Opportunity> opportunityList){
populateOpp(opportunityList);
}
public static void onBeforeUpdate(List<Opportunity> opportunityList, Map<Id,Opportunity> opportunityId){
populateOppDescription(opportunityList, opportunityId);
}
public static void populateOpp(List<Opportunity> opportunityList){
for(Opportunity opp : opportunityList){
if(opp.StageName == 'Closed Won'){
opp.Description = 'This Opportunity is Closed Won';
}
}
}
public static void populateOppDescription(List<Opportunity> opportunityList, Map<Id,Opportunity> opportunityId){
for(Opportunity opp : opportunityList){
Opportunity oldOpp = opportunityId.get(opp.Id);
Boolean oldStage = oldOpp.StageName.equals('Closed Won');
Boolean newStage = opp.StageName.equals('Closed Won');
if(!oldStage && newStage){
opp.Description = 'This Opportunity is Closed Won';
}
}
}
}
public static void onBeforeInsert(List<Opportunity> opportunityList){
populateOpp(opportunityList);
}
public static void onBeforeUpdate(List<Opportunity> opportunityList, Map<Id,Opportunity> opportunityId){
populateOppDescription(opportunityList, opportunityId);
}
public static void populateOpp(List<Opportunity> opportunityList){
for(Opportunity opp : opportunityList){
if(opp.StageName == 'Closed Won'){
opp.Description = 'This Opportunity is Closed Won';
}
}
}
public static void populateOppDescription(List<Opportunity> opportunityList, Map<Id,Opportunity> opportunityId){
for(Opportunity opp : opportunityList){
Opportunity oldOpp = opportunityId.get(opp.Id);
Boolean oldStage = oldOpp.StageName.equals('Closed Won');
Boolean newStage = opp.StageName.equals('Closed Won');
if(!oldStage && newStage){
opp.Description = 'This Opportunity is Closed Won';
}
}
}
}
Raj Vakati
i guess you can calling above code from the trigger so use this code