+ Start a Discussion
Salesforce BlitzSalesforce Blitz 

Need to fetch User ids from User Emails of a Object field

I have a field named recepient which contains both Salesforce users and Non salesforce users EMAIL IDS.
I need to SOQL to find the User Ids of Salesforce Users and exclude the Non Salesfoerce users.

How do I need to achieve this
Hey jagz

First you have to query the recepient email ids and take it to a list say list<id> RecepientId.
then do the following code
list<user> UserId= [select id,name from user where Email in :RecepientId];

this will do your requirement.

PS: Pls mark as best answer if it helped
Salesforce BlitzSalesforce Blitz
Hey Eldon,

Thanks for reply.

Consider I have field with 5 email ids(comma seperated) in a text field. Out of 5 only 3 are SF users and remaining 2 aren't.
How do I query if i have multiple email ids in one field as above

Field contains: 12@abc.com, 34@abc@.com, 56@abc.com, 78@abc.com, 90@abc.com
Out of these only first 3 emails have salesforce users and last 2 doesnt have.
How do I perform SOQL in this case


For that first you need to split your string field with comma.Try something like below,
string str=' 12@abc.com, 34@abc@.com, 56@abc.com, 78@abc.com, 90@abc.com';
List<String> ReciepientMail= str.split(',');
list<user> UserId= [select id,name from user where Email in :ReciepientMail];