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
devamitdevamit 

Opportunity Owner not changing in before update trigger.

Hi Guys,

 

I have stuck up on an issue in which requires your input.

 

I need to update the opportunity owner with Account Owner only when Keep manual flag is unchcecked. If flag is checked then even if Opportunity owner is changing, Account Owner will become opportunity Owner.

 

Please see the code below:

for

(Opportunity objopp: Trigger.new){

setAccountid.add(objopp.AccountId);

}

lstAcc = [ Select Ownerid,name fromAccountwhere id IN:setAccountid];

 

system.debug('lstAcc-->'+lstAcc);

 

/* Updating the Opportunity Owner with Account owner field */for(Opportunity objopp: Trigger.new){

 

if(objopp.Keep_Manual_Primary_Flag__c == false){

 

for(Accountobjacc: lstAcc){

 

if(objacc.id == objopp.AccountId ){

objopp.OwnerId = objacc.OwnerId;

setOwnerid.add(objopp.OwnerId);

system.debug('setOwnerid1--->'+setOwnerid);

}

}

}

}

 

Above code is working fine for insert operation but it's not working in Update operation when I am changing the owner from 'Change' link.

It was working before Winter 12 release.

 

Waiting for your feedback.