You need to sign in to do that
Don't have an account?
Problem changing some fields in Opportunity
Hello,
I need to check to see when an opportunity is set to isWon and take a few actions on it and some other objects. I created a trigger that fires on all of the after events for opportunity and reads the isWon boolean on the list of incoming opportunity objects. OK, so far, so good. Now my problem is that I'm writing a test where I create an opportunity object but I need to set the isWon field. Apparently that is a read-only field. I tried setting the stageName to 'Closed/Won' but that didn't change the isWon field. How can I simulate the closing of an opportunity into the 'Closed/Won' state and set the isWon field?
Regards,
Tim
You have to update the Opportunity StageName field from a non-closed/won value, to a closed/won value. Make sure when you set the StageName property in your test case that you use the exact same spacing and capitalization as the "Won" picklist value from the Stage field.
That sounds very reasonable, however my test tells me that I am not getting the results I had hoped for. Here is a snippet from my test code:
The trigger that is kicked off by the update has a System.debug statement that tells me the value of the isWon field:
And unfortunately my output is not what I'd like to see:
I was expecting to see Trigger.new.isWon = true
Any ideas what I might be doing wrong here?
Regards,
Tim
It should look something like this:
Your test case would look something like this:
Let me know if you have any questions...