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
Khalid AbdullahKhalid Abdullah 

SOQL: How do I select accounts where the owner's record is frozen?

Hi all,

I'm looking to create a simple SOQL query which brings back all accounts based on whether or not the owner's record isfrozen.

I've been trying variations of the following SOQL: Select name from ACCOUNT where Account__r.owner in (select isfrozen from userlogin where isFrozen = true) 

So far I have had no luck. Would anyone be able to help me? I am relatively new to SOQL and would appreciate any help I can get :-)
Best Answer chosen by Khalid Abdullah
Ravi Dutt SharmaRavi Dutt Sharma
List<UserLogin> frozenUserList = [SELECT UserId FROM UserLogin WHERE IsFrozen=TRUE];

Set<String> frozenUserIdSet = new Set<String>();

for(UserLogin usr : frozenUserList){
      frozenUserIdSet.add(usr.UserId);
}

List<Account> accList = [SELECT Id FROM Account WHERE OwnerId IN: frozenUserIdSet ];

 

All Answers

Ravi Dutt SharmaRavi Dutt Sharma
List<UserLogin> frozenUserList = [SELECT UserId FROM UserLogin WHERE IsFrozen=TRUE];

Set<String> frozenUserIdSet = new Set<String>();

for(UserLogin usr : frozenUserList){
      frozenUserIdSet.add(usr.UserId);
}

List<Account> accList = [SELECT Id FROM Account WHERE OwnerId IN: frozenUserIdSet ];

 
This was selected as the best answer
Khalid AbdullahKhalid Abdullah
Thank you Ravi! This seems to get me close. However, if I wanted to System.debug this as a table, how would I do that? Right now it's bringing the data I want, but not in a table, and when I try: system.debug(accList) it brings back the information on the same row
Ravi Dutt SharmaRavi Dutt Sharma
for (Account acc : accList ){
        System.debug('Acc info :'+acc);
}
You can try this, let me know if it works for you. Thanks.
 
Khalid AbdullahKhalid Abdullah
Very impressed!
Ravi Dutt SharmaRavi Dutt Sharma
Glad that it helped you.