When the account records transferred to another user, the associated open opportunities automatically transferred to the new account owner without firing the opportunity trigger.
See my post (Account Owner changes Opportunity Owner?)
So I added code in account trigger to invoke the opportunity trigger by updating a hidden field on opportunity.
But in test class, when I change the account's ownerid, the associated opportunity ownerid is not changed by system automatically. And if I manually change the opportunity ownerid in the test class, it's like testing the opporutnity trigger.
So what's my options here? Thanks
private void updateOpptyOwnerRoleInfo()
{
System.debug(LoggingLevel.INFO,'Enter method UpdateOpptyOwnerRoleInfo of AccountHandler');
if (isBefore && isUpdate)
{
List<Id> lstAcctIds = new List<Id>();
for (Account acct : newList)
{
Account oldAcct = oldMap.get(acct.Id);
if (acct.OwnerId != oldAcct.OwnerId)
{
lstAcctIds.add(acct.Id);
}
}
if (lstAcctIds.size() > 0)
{
System.debug(LoggingLevel.INFO,'Number of Account updated: '+lstAcctIds.size());
For(Opportunity opp : [Select Id, HiddenUpdateFlip__c from Opportunity where AccountId in :lstAcctIds]){
opp.HiddenUpdateFlip__c='OVERRIDE:UPDATEOPPTYOWNERROLEINFO';
accountDispatcher.sObjUpdLIST.add((sObject)opp);
//OpportunityDispatcher.preventRecursion = true;
}
}
}
}