I've a simple conceptual doubt - Would really appreciate if someone would explain me the reason for this behaviour:

I'm inserting a new contact from console and following is the snippet:

Contact c = new Contact();
c.Email = '[email protected]';
c.LastName = 'TEST';
c.CurrencyIsoCode = 'USD';
insert c;

I've written a simple before insert trigger which would check if the Email is not null then would make the Email lower case and add '.com' to it.

  For(Contact c: newCon){
            if(c.Email != null){
                c.Email = c.Email.toLowerCase() + '.com';

So when I'm running the first snippet in developer console the debug result is [email protected]

Shouldn't it be [email protected] since before trigger will be acting upon it?

I'm getting [email protected] only when I run the following snippet along with the first snippet:

Contact newCon = [SELECT Id, Email FROM Contact Where Id = :c.Id LIMIT 1];
System.debug('+++ After Insert Email Value: '+newCon.Email);

1 Answer 1


When you perform DML on a record, the "in memory" instance (i.e. your c variable) of your object is not automatically updated1.

If you re-query the record, and debug the email value, you would see "[email protected]" as you expect.

If you don't re-query the record, the in-memory field values remain untouched.

As a side note, explicitly transforming the email to lower case is not necessary if you're working with an email type field (and not something like, say, a text field). Salesforce automatically makes emails all lower case (learned that one the hard way some months ago).

1: If you're inserting a record, after the DML completes, the in-memory instance will be updated to contain the Id (and recordTypeId too, I believe, if you have multiple recordtypes for that particular object)

  • Thanks Derek F - I had the same doubt, so does it mean that only Id and RecordTyepId of the 'in memory' instance is updated and everything else is left untouched?? If yes, are there any other fields that are also updated in the 'in memory' instance?
    – sfdcnewbie
    Commented Jan 11, 2020 at 16:33
  • It will be great if you could help me with where I could find the documentation around it :)
    – sfdcnewbie
    Commented Jan 11, 2020 at 16:35
  • @sfdcnewbie That only happens for inserts, and only those fields. No documentation on that as far as I know.
    – Derek F
    Commented Jan 11, 2020 at 16:44
  • 2
    In case you are interested, you can ask Salesforce to recalculate formula fields in the in-memory instance without an explicit re-querying of the object using SObject.recalculateFormulas. This does, however, count towards your query limits. It may be useful if you are simply wanting formula values for a single object that you just updated.
    – Phil W
    Commented Jan 11, 2020 at 17:51

You must log in to answer this question.

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