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
Proposal ButtonProposal Button 

Test class for a trigger

Hi All

 

Can you please help me out in writter a test class for the following Trigger. Appreciate your help in advance

 

trigger CaseUpadate on Opportunity (after update)
{
List <Case> caseList;
List <Id> oppIdList = new List <Id>();
for(Integer i=0; i<Trigger.new.size(); i++)
{
    if (Trigger.new[i].StageName != Trigger.old[i].StageName && (Trigger.new[i].StageName == 'Closed Won' || Trigger.new[i].StageName == 'Closed - Dead/Lost'))
        
        oppIdList.add(Trigger.new[i].Id);
}   
caseList = [select Id, Opportunity_closed_won__c from Case where Opportunity__c in :oppIdList];
if (caseList.size() > 0)
{
    for(Case c : caseList)
    {
        if (c.Opportunity_closed_won__c != true)
            c.Opportunity_closed_won__c = true;    
    }
    
    update caseList;
    }
}