I have below trigger code :
trigger updateopportunities on Account(after update)
{
Set<Id> accountIds = new Set<Id>();
for(Account ac : Trigger.new)
{
if(ac.Status__c=='Cancelled')
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 - Cancelled';
oppsToUpdate.add(opp);
}
update oppsToUpdate;
}
And below is one of the Test Method for single record testing
@isTest
Public Class TestAccountOpportunity{
public static testMethod void verify(){
List<Account> accounts = new List<Account>{};
Account a = new Account(Name = 'Test Account');
insert a;
Opportunity opp =new opportunity(Name='TestOpportunity',accountid=a.id,StageName='Prospecting',CloseDate=system.today(),Amount=1000);
insert Opp;
a.status__c = 'Cancelled';
update a;
system.assertequals(opp.stageName,'Closed - Cancelled');
}
}
The expected output as per trigger should be the stage value of Opportunity is 'Closed - Cancelled' . But System.assertequals still shows it as 'Prospecting' only. Any idea on whats going wrong.