Within the Salesforce Triggers and Order of Execution documentation, the Save step is listed as:

  • Saves the record to the database, but doesn't commit yet.

What happens when a record is saved? Is a Salesforce ID and autonumber (if applicable) assigned? At which step are formula fields calculated? What is the difference between this step and the commit step listed below?

  • Commits all DML operations to the database.

A save writes your changes to the database, however at this point these changes are only visible to you within your transaction scope. The database has also generated undo information which contains the old values of your transaction which can be used to rollback your modifications.

A commit ends the current transaction and makes permanent all changes performed in the transaction. The transaction is a sequence of SQL statements that the database treats as a single unit. A commit also erases all savepoints in the transaction and releases transaction locks. After your data is committed, it is visible to other users of the system.

  1. What happens when a record is saved?
    • Your data is stored and can still be rolled back to its previous values.
  2. Is a Salesforce ID and autonumber (if applicable) assigned?
    • Yes
  3. At which step are formula fields calculated?
    • Formulas are calculated when the data is read, not when it is written.
| improve this answer | |
  • Are formula fields calculated when queried as well, then? (Such as: select formula_field__c from Account) – Matt K Jun 16 '15 at 16:17
  • 4
    Yes. That's what I meant by 'when the data is read'. When you demand a formula field's value, the value is calculated and shown to you on the fly. It is not stored on the record. – Mark Pond Jun 16 '15 at 16:23
  • Great to know! Thank you for your thorough answer. – Matt K Jun 16 '15 at 16:27

I don't know exactly if this is applicable to Salesforce, but I believe the difference is that the data is saved when the trigger is running (Save to Database), and then, when the Trigger enters the "finish" status, it commits these changes (saves) to the Database.

In a similar way, when working with a file in a git repository, if you save the file, git won't track the changes you made until you commit them (the file is saved locally, but not committed).

| improve this answer | |

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.