You need to sign in to do that
Don't have an account?
Vidya H 4
hi can anyone help me to write test class for this code
trigger AccountStage on Account (After Update) {
Set<Id> accountIds = new Set<Id>();
for(Account ac : Trigger.new)
{
if(ac.Stage__c =='Closed')
accountIds.add(ac.Id);
}
List<Opportunity> oppsToUpdate = new List<Opportunity>();
for(Opportunity opp : [select id, StageName from Opportunity where AccountId in: accountIds])
{
opp.StageName='Closed - won';
opp.closeDate=Date.today();
oppsToUpdate.add(opp);
}
update oppsToUpdate;
}
Set<Id> accountIds = new Set<Id>();
for(Account ac : Trigger.new)
{
if(ac.Stage__c =='Closed')
accountIds.add(ac.Id);
}
List<Opportunity> oppsToUpdate = new List<Opportunity>();
for(Opportunity opp : [select id, StageName from Opportunity where AccountId in: accountIds])
{
opp.StageName='Closed - won';
opp.closeDate=Date.today();
oppsToUpdate.add(opp);
}
update oppsToUpdate;
}
Try Below Code Please Mark It As Best Answer If It Helps
Thank You!