function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
jhartjhart 

Data consistency bug: Contact/Lead triggers skipped when Email is updated via Send Email page

If you send an email to a Contact or Lead from the Activity History "Send an Email" interface, and the Contact/Lead has a blank Email address, you are prompted to enter an Email address:


 

 

 

If you click "Save Address" or "Save Address and Send", the Contact/Lead will be updated with the given address.


However, no Contact or Lead triggers fire for this update (this is the bug).

 

Any app logic that depends on Contact/Lead triggers to detect Email address changes will therefore be left in an inconsistent state.


To verify this, I wrote a quick trigger for the Contact object:

 

trigger logEmailUpdate on Contact bulk (after delete, after insert, after update, after undelete) {
  string addrs = '\n';
    for (integer i=0; i<Trigger.size; i++) {
      addrs += string.format('[{0}]: Email changing from "{1}" to "{2}"\n', new string[] {
        '' + i,
        Trigger.isInsert ? '(isInsert - no old record)' : Trigger.old[i].Email,
        Trigger.isDelete ? '(isDelete - no new record)' : Trigger.new[i].Email
        });
      }

  AALog.log('DEBUG', 'Contact trigger fired '
    + (Trigger.isBefore ? 'before' : '')
    + (Trigger.isAfter  ? 'after'  : '')
    + ' '
    + (Trigger.isInsert ? 'insert' : '')
    + (Trigger.isUpdate ? 'update' : '')
    + (Trigger.isDelete ? 'delete' : '')
    + (Trigger.isUndelete ? 'undelete' : '')
    + ', email changes are '
    + addrs
    );
  }

 

The "AALog.log" method here writes a row to a simple logging object.


I then created a new Contact with a null address via the UI:


Contact trigger fired after insert, email changes are 
[0]: Email changing from "(isInsert - no old record)" to "null"

 I then went through the "Send Email" interface as shown above & updated the Email address that way.

The trigger was not called, however the Contact was updated.

The very next thing I did was edit the Contact to delete the (silently updated) Email address.  As expected, the trigger fired:


Contact trigger fired after update, email changes are 
[0]: Email changing from "test@ihance.com" to "null"

 

Note that the Email addr is already set, even though our trigger was never called for that update.

I then updated the Contact via the normal UI to set its Email field, to verify the trigger output is as expected:


Contact trigger fired after update, email changes are 
[0]: Email changing from "null" to "test@ihance.com"

 

This is what we should have seen when the Contact was updated from the "Send Email" dialog.

 

Finally I deleted the Contact altogether:


Contact trigger fired after delete, email changes are 
[0]: Email changing from "test@ihance.com" to "(isDelete - no new record)"

 Note that all actions invoke the trigger except the Email update done via the Send Email interface.


Leads have the exact same bug.

 

 

Salesforce support - I created case 05987983 to track this issue.

jhartjhart

OK, the guys at salesforce support are getting hung up on the AALog method & cannot compile, so to make it super simple:

 

trigger logEmailUpdate on Contact bulk (after delete, after insert, after update, after undelete) {
  string addrs = '\n';
    for (integer i=0; i<Trigger.size; i++) {
      addrs += string.format('[{0}]: Email changing from "{1}" to "{2}"\n', new string[] {
        '' + i,
        Trigger.isInsert ? '(isInsert - no old record)' : Trigger.old[i].Email,
        Trigger.isDelete ? '(isDelete - no new record)' : Trigger.new[i].Email
        });
      }

  insert new Account(Name = 'DEBUG', Description = 'Contact trigger fired '
    + (Trigger.isBefore ? 'before' : '')
    + (Trigger.isAfter  ? 'after'  : '')
    + ' '
    + (Trigger.isInsert ? 'insert' : '')
    + (Trigger.isUpdate ? 'update' : '')
    + (Trigger.isDelete ? 'delete' : '')
    + (Trigger.isUndelete ? 'undelete' : '')
    + ', email changes are '
    + addrs
    );
  }

 

To view the logging output, run this:

 

System.debug([select CreatedDate, Description from Account where Name = 'DEBUG' order by CreatedDate asc]);