Trigger.old won't hold the newly updated field by the workflow after the update.

Considerations

  • You have a workflow on an object creation - say Account - that updates a field - for example "description" field.
  • You then have a trigger that fires after the workflow update and iterates over trigger.old expecting to get the "description" field that was modified by the workflow.
  • In this case you will get a nullpointerException.


The reason comes down to understanding the values held by these 2 data structures.
Trigger.old values will be the same before and after the CURRENT transaction (user action). The same applies to Trigger.new.
In other words - Trigger.old won't hold the newly updated field by the workflow after the update. However, if we proceed to manually edit the record, the trigger will fire again (and this is viewed as a new “update transaction”). Trigger.old will hold the field that was updated on the previous transaction by the workflow rule.
Going back to the example above: 
The values in Trigger.old after the workflow update will NOT contain the “description” field that was updated in the workflow.
The values in Trigger.new after the workflow update will contain any existing fields that were populated upon the object’s creation AND the “description” workflow updated field.
You'll have to query the database after the workflow field update fires In order to obtain that same field.
For example:
 
1List<Account> accts = [Select Id, FieldUpdatedByWorkflow__c from Account where Id in : Trigger.old];

See the sample trigger bellow.
Note: Create a workflow field update on Account objects creation to see the results in the debug log.
trigger testTrigger on Account (before update, after update, before insert, after insert) 


{
    if (Trigger.isBefore) {
        System.debug('********Trigger values***********');
        System.debug('***SFDC: Trigger.old is: ' + Trigger.old);
        System.debug('***SFDC: Trigger.new is: ' + Trigger.new);
    }
    
    if (Trigger.isAfter) {
        System.debug('********Trigger values***********');    
        System.debug('***SFDC: Trigger.old is: ' + Trigger.old);
        System.debug('***SFDC: Trigger.new is: ' + Trigger.new);
       
    }
}

Transaction Control

All requests are delimited by the trigger, class method, Web Service, Visualforce page or anonymous block that executes the Apex code. If the entire request completes successfully, all changes are committed to the database. For example, suppose a Visualforce page called an Apex controller, which in turn called an additional Apex class. Only when all the Apex code has finished running and the Visualforce page has finished running, are the changes committed to the database. If the request does not complete successfully, all database changes are rolled back.
Sometimes during the processing of records, your business rules require that partial work (already executed DML statements) be “rolled back” so that the processing can continue in another direction. Apex gives you the ability to generate a savepoint, that is, a point in the request that specifies the state of the database at that time. Any DML statement that occurs after the savepoint can be discarded, and the database can be restored to the same condition it was in at the time you generated the savepoint.
The following limitations apply to generating savepoint variables and rolling back the database:
  • If you set more than one savepoint, then roll back to a savepoint that is not the last savepoint you generated, the later savepoint variables become invalid. For example, if you generated savepoint SP1 first, savepoint SP2 after that, and then you rolled back to SP1, the variable SP2 would no longer be valid. You will receive a runtime error if you try to use it.
  • References to savepoints cannot cross trigger invocations because each trigger invocation is a new trigger context. If you declare a savepoint as a static variable then try to use it across trigger contexts, you will receive a run-time error.
  • Each savepoint you set counts against the governor limit for DML statements.
  • Static variables are not reverted during a rollback. If you try to run the trigger again, the static variables retain the values from the first run.
  • Each rollback counts against the governor limit for DML statements. You will receive a runtime error if you try to rollback the database additional times.
  • The ID on an sObject inserted after setting a savepoint is not cleared after a rollback. Create an sObject to insert after a rollback. Attempting to insert the sObject using the variable created before the rollback fails because the sObject variable has an ID. Updating or upserting the sObject using the same variable also fails because the sObject is not in the database and, thus, cannot be updated.
The following is an example using the setSavepoint and rollback Database methods.
01Account a = new Account(Name = 'xxx'); insert a;
02System.assertEquals(null, [SELECT AccountNumber FROM Account WHERE Id = :a.Id].
03                           AccountNumber);
04 
05// Create a savepoint while AccountNumber is null
06Savepoint sp = Database.setSavepoint();
07 
08// Change the account number
09a.AccountNumber = '123';
10update a;
11System.assertEquals('123', [SELECT AccountNumber FROM Account WHERE Id = :a.Id].
12                             AccountNumber);
13 
14// Rollback to the previous null value
15Database.rollback(sp);
16System.assertEquals(null, [SELECT AccountNumber FROM Account WHERE Id = :a.Id].
17                            AccountNumber);

Counters