I'm doing some tests for triggers and I'm seeing that Trigger.Old is returning the new values of the updated object , instead of the old values. I'm assigning the values to a List, so I can then access them with that variable. Here is the code that I use:

trigger testTrigger on Account (after update) {
List<Account> allAccounts=[select Id,ACV from Account where Id IN: Trigger.newMap.keySet() ];
List<Account> allOldAccounts= [select Id,ACV from Account where Id IN: Trigger.old ];

System.debug('Value of New Accounts: '+allAccounts);
System.debug('Value of old Accounts: '+allOldAccounts);

If I go and change ACV from 0 to 777, I expect to see for the first debug line, the new value of 777, and for the old value 0. That is not the case, and both of them are returning the NEW value of 777.

Any idea what I'm doing wrong?

1 Answer 1


You aren't accessing the data in Trigger.old: you're using it to query the database, where the new values have already been persisted because you are in after update context.

If you access the sObject instances in Trigger.old and Trigger.oldMap directly, you will see the pre-change values.

  • 1
    I have used this querying format for a while now, that I forgot what it was doing. Thank you!
    – Neto0291
    Feb 22, 2021 at 16:34

You must log in to answer this question.

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