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
S_BatmanS_Batman 

Leads email domain in custom field

I want to create a custom field that parses the domain of an email and inserts it in there through a trigger.  Could someone help me create that trigger please?

i.e. if Leads email is jonsmith@abc.com    then custom field = abc.com 
Best Answer chosen by S_Batman
John Pipkin 14John Pipkin 14
S_Batman, 

You can do this declaratively with a formula field:

IF(NOT(ISBLANK(Email)),RIGHT(Email,LEN(Email)-FIND('@',Email)),null)

Hope that helps

All Answers

John Pipkin 14John Pipkin 14
S_Batman, 

You can do this declaratively with a formula field:

IF(NOT(ISBLANK(Email)),RIGHT(Email,LEN(Email)-FIND('@',Email)),null)

Hope that helps
This was selected as the best answer
S_BatmanS_Batman
Thanks John!
 
S_BatmanS_Batman
Is there a way to do this on the Account level based on the contacts' email domain?

So I want a custom field on the Account level that again fills with the contact's email domain.
John Pipkin 14John Pipkin 14
S_Batman, 

You can do this with a process. The formula for the field update would be 
IF(NOT(ISBLANK([Contact].Email)),RIGHT([Contact].Email,LEN([Contact].Email)-FIND('@',[Contact].Email)),null)

1. Create a process on contact
2. Criteria :
ISCHANGED([Contact].Email)
&&
NOT(ISBLANK([Contact].Email))

3. Action: Update Records > Account ID
4. [Your email domain field] FORMULA and insert the formula above. 

Hope that helps!
S_BatmanS_Batman
Hey John,

I am following your steps, and on step 3 when I select Account ID I am getting the following error
User-added image
John Pipkin 14John Pipkin 14
Is that from the Process Builder?
S_BatmanS_Batman
Yes, but I am not longer getting that error.

However, the email domain field on my Account level is not populating.  

The email domain field on the Account level I created  as a text field and inserted the formula you mentioned in the process builder.

My accounts have multiple contacts, but it does not matter which Contacts email domain it uses as they all have the same email domain.

 
John Pipkin 14John Pipkin 14
The process will only fire when a contact's email address changes to a non-null value. Did you make that update to a contact? Also, is the process activated?

 
S_BatmanS_Batman
The process is activated and i deleted the email address of a Contact  saved it then reinserted the email address again and saved it, but unfortunately not getting anything to populate on that field.

Just to make sure I did it correctly, here are my steps

- Object = Contact, start process when a record is created/edited
- Criteria for Executing Actions = Formular evaluates to true & formula is 
ISCHANGED([Contact].Email)
&&
NOT(ISBLANK([Contact].Email))

- if True = Actiona Name = Update Record
                       Record = [Contact].Account ID
- Criteria for Updating Records = No Criteria - just update the records

- Set new field values for the records you update
                   Field = Email Domain
                   Type = Formula
                    Formula = IF(NOT(ISBLANK([Contact].Email)),RIGHT([Contact].Email,LEN([Contact].Email)-FIND('@',[Contact].Email)),null)



 
John Pipkin 14John Pipkin 14
That's right. Are you using the Contact standard email field? I implemented this in a dev org and it is working for me
S_BatmanS_Batman
Figured out the issue - I changed the email domain field name after i build the process, so it was not recognizing the field.

Thanks a lot for your help!
John Pipkin 14John Pipkin 14
No problem!