I have the following trigger for Opportunity

trigger OpportunityTrigger on Opportunity (before update) { 
    for(Opportunity o : Trigger.new){ 
        o.OwnerId = 'some Id'; 

When I update an owner via UI the Trigger works fine, but owner's value on UI is succsessfully updated on new.

For reproduction you can

  1. enable History Tracking for Opportunity Owner
  2. add Related List "Opportunity Field History" to Opportunity Layout
  3. open an existing opportunity and change owner to other user.
  4. check "Opportunity Field History" You will see 3 events as follows.

    • Changed Opportunity Owner from "A" to "B". <- change by UI
    • Changed Opportunity Owner from "B" to "A". <- change by Apex trigger
    • Changed Opportunity Owner from "A" to "B". <- unexpected change

    *A is the original owner. B is changed owner.

Any ideas. Maybe, is there official documentation which describes this behavior.

UPDATE! I have only trigger for opportunity and no one workflow

  • IS there any other triggers on Opps?
    – EricSSH
    Jun 16 '14 at 21:04
  1. Do you have more than one trigger on Opportunity object? You can verify this by going to "Opportunities > Triggers" in the setup.
  2. Do you have some workflow rules on Opportunity? Check "Field Updates" in setup, you can fairly easily filter the list by Object type.

You can also examine the debug log (enable tracing on yourself or open up the Developer Console) for some insight.

Nope, works OK in my org (I had to deactivate all workflows on Opportunity though, otherwise I was getting "before update" trigger firing twice which looks similar to what you describe).

enter image description here

Check What would cause a trigger to execute twice? for example... If you're sure you don't have workflows on Opportunity - edit your question & include debug log for example?

  • I'd suspect territory management as a possible culprit, too.
    – sfdcfox
    Jun 17 '14 at 3:27
  • I have only trigger for opportunity and no one workflow Jun 17 '14 at 15:02
  • Do you see anything interesting in the debug log? You can open Developer Console, update the Opp and then in the logs tab in console open the log. Filter it by "owner", see if anything pops up
    – eyescream
    Jun 17 '14 at 17:23
  • I think it is standard SFDC behavior, could you try reproduce this case on your box? Jun 18 '14 at 20:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.