You need to sign in to do that
Don't have an account?

TestDataFactory and OpportunityHandlerTest How to?
Hello,
Would like to ask on how to create a testdatafactory and test class for the following code below?
Trigger Handler:
Thank you!
Would like to ask on how to create a testdatafactory and test class for the following code below?
Trigger Handler:
public class OpportunityTriggerHandler { public static void onBeforeUpdate(List<Opportunity> oppList, Map<Id, Opportunity> oldStageMap){ oppNewStage(oppList, oldStageMap); } public static void oppNewStage(List<Opportunity> oppList, Map<Id, Opportunity> oldStageMap){ for(Opportunity opp : oppList){ //Compare the old stage status and new stage status. Opportunity oldOppID = oldStageMap.get(opp.Id); if(oldOppID.StageName !=opp.StageName){ if(opp.StageName == 'Closed Won'){ opp.Description = 'This Opportunity is Closed Won.'; } } } } }And Trigger is:
trigger OpportunityTrigger on Opportunity (before update) { if(Trigger.isBefore) { if(Trigger.isUpdate){ OpportunityTriggerHandler.onBeforeUpdate(Trigger.new, Trigger.oldMap); } } }
Thank you!
All Answers
On your test method you would call the TestDataFactory and create one or more Account records, then query the account object to get the id's of the records created. With than info you can then add Opportunity records that will trigger your trigger class. Afterwards you can query the opportunity object to see if you get the expected results.
But i'm stuck with my Test Class, any idea?