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
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
EldonEldon
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.

Thankyou.
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

Ex:
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

thanks
EldonEldon
Hi

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(',');
system.debug('ele'+ReciepientMail);
list<user> UserId= [select id,name from user where Email in :ReciepientMail];

Regards