Invalid Email trigger

One of the quirks of Salesforce is that it will allow invalid Email addresses to be stored in Email fields when a lead is inserted from an external source such as Web-to-Lead.

This causes an issue for DE, because Email fields are automatically validated by Salesforce on any update. Salesforce will not allow any updates until the Email address is fixed. So the lead has entered the system, but DE cannot update it to assign a new owner.

The best solution is to catch invalid Email addresses on your website. But as a fallback option an apex trigger such as the one below will move any invalid Emails to the description allowing the lead to be assigned out without error.


trigger InvalidEmailTrigger on Lead (before insert, before update){
    String validEmailRegex = '[a-zA-Z0-9._-]+@[a-zA-Z]+.[a-zA-Z]{2,4}';
    Pattern EmailPattern = Pattern.compile(validEmailRegex);
       List<Lead> leadsToCheck =;
    for(Lead thisLead : leadsToCheck){
        String thisEMail = thisLead.Email;
        if(thisEmail == null){
        Matcher EmailMatcher = EmailPattern.matcher(thisEMail);
            thisLead.description += ' invalid Email entered: ' + thisEmail;
            thisLead.Email = '';

How did we do?

Salesforce Presence Integration

Custom Triggers