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
vamshi Capvamshi Cap 

How to fetch the User with email Id condition in SQL

Hi I need to fetch the User records on the basis of email Id using SQL queries. Requirement we have three objects.
1. Service
2. Account
3. Cycle30Account.

I have written a query get the email Id from the cyclec30 Account from the service object whose status is suspend.

SELECT Prepaid80__Email_Address__c FROM Prepaid80__Cycle30Account__c where Prepaid80__Account__c in (SELECT Prepaid80__Account__c From Prepaid80__Service__c WHERE Prepaid80__Status__c = 'DISCONNECTED')

now with these email Id I need to fetch User Ids.


can please some one help.



Tarun J.Tarun J.
Hello Vamshi,

If your query return more than one record, you need to store all emails in a list. If it is returning single email, you can directly use that one.

Use below query to fetch user records:
1. For emails in List (variable name: emailList):
List<User> usrLst = [SELECT Id, Name, Email FROM User WHERE Email IN: emailList ];

2. For single record:
List<User> usrLst = [SELECT Id, Name, Email FROM User WHERE Email =: Prepaid80__Cycle30Account__c.Prepaid80__Email_Address__c ];


Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.
use this list from soql
set<string> emails = new set<string>();
for(Prepaid80__Service__c ps : list){
emails.add(ps.Prepaid80__Email_Address__c );
now list<user> userlist = new list<User>([Select id from user where email=:emails]);