+ Start a Discussion
Amit Singh 1Amit Singh 1 

Urgent : Get Name From Email Id Using Apex

Hello Experts,

I have an urgent requirement in which I need to fetch the Email owner Name from email. Scenaron is given below :

1) I am sending an email from my email using email to case functionality.
2) If cpontact exists then it automaticaly attached that contact with the newly created case.
3) I am facing the problem when contact is not existing then I need to create contact with the actual name that is used into email for example my email id is testing@gmail.com and Name in gmail is Amit Singh then I need to insert contact as Amit Singh and email as testing@gmail.com

Any help will be greatly appreciated.

Please help :)

Thanks!
Amit Singh
Best Answer chosen by Amit Singh 1
LBKLBK
Hey Amith,

You need to fetch the name from the EmailMessage object.

Here is the SOQL query sample for you.
 
SELECT ID, FromName, FromAddress, ValidatedFromAddress FROM EmailMessage
FromName is your field to fetch.

I suggest a Trigger or a Process on the EmailMessage object.

I believe ValidatedFromAddress would be blank in EmailMessage, if Contact is not present (But, I would let you validate this).

Let me know how it goes.
 

All Answers

LBKLBK
Hey Amith,

You need to fetch the name from the EmailMessage object.

Here is the SOQL query sample for you.
 
SELECT ID, FromName, FromAddress, ValidatedFromAddress FROM EmailMessage
FromName is your field to fetch.

I suggest a Trigger or a Process on the EmailMessage object.

I believe ValidatedFromAddress would be blank in EmailMessage, if Contact is not present (But, I would let you validate this).

Let me know how it goes.
 
This was selected as the best answer
Amit Singh 1Amit Singh 1
Thank You so much it works.

Thank you.

Amit Singh