function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Vidya H 4Vidya 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 :
         if(ac.Stage__c =='Closed')

     List<Opportunity> oppsToUpdate = new List<Opportunity>();

     for(Opportunity opp : [select id, StageName from Opportunity where AccountId in: accountIds])
          opp.StageName='Closed - won';

     update oppsToUpdate;

Best Answer chosen by Vidya H 4
Hii Vidya
Try Below Code
public class AccountStage Test{
    public Static Void UnitTest(){
        Account Ac =new Account();
        Acc.Name = 'Account test';
        Insert Acc;
        Opportunity opp = new Opportunity();
        opp.Name = 'test opp';
        opp.Stagename = 'Prospect';
        opp.CloseDate = System.toda()-5;
        opp.AccountId = Acc.Id;
        insert Opp;
        Acc.Stage__c = 'Closed';
        update Acc;
Please Mark It As Best Answer If It Helps
Thank You!