0

I have the following code at the very beginning of my account trigger:

switch on Trigger.operationType {
    when BEFORE_UPDATE {
        for (Account account : Trigger.new) {
           system.debug(account.BillingState);
           system.debug(account.Website);
        }
    }
}

Let's say I have an account where the BillingState/Website combination is Alabama/Website1, then I update the account to Colorado/Website2. In this scenario, the resulting debug logs show Alabama/Website2.

The update does go through correctly. The state is successfully set to Colorado. The issue is that my BEFORE_UPDATE trigger doesn't see Colorado, it sees Alabama.

What's going on? Why is my code retrieving the old version of BillingState, but not the old version of other fields?

1 Answer 1

2

Presuming you're using State and Country picklists, this is expected behavior. The BillingStateCode and BillingCountryCode would appear correct, but the BillingState and BillingCountry fields will be incorrect until the after insert/after update phase of the triggers.

2
  • sfdcfox, do you know why salesforce made this the expected behavior? Seems weird that the value would only be reflected after the commit
    – willard
    Feb 28 at 2:29
  • @willard See Triggers and Order of Execution. During Step 1, the old values are loaded from the database. During Step 2, the new values are applied; since the codes were supplied, but not the state/country fields, they're not updated yet. During Step 7, the record is saved and loaded again. At this point, all formulas and calculations are now correct. It's not well-documented, but it is consistent.
    – sfdcfox
    Feb 28 at 2:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .