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
Kalyani Jagdale 1Kalyani Jagdale 1 

How can i retrieve account records in which zero contacts available ?

How can i retrieve account records in which zero contacts available ?

Please reply, how can i achieve this?

Thanks in advance.
Best Answer chosen by Kalyani Jagdale 1
Rahul.MishraRahul.Mishra
Hi,

This can not be achive in a single query, however we can do that with couple of queries, below is the code:
 
Set<Id> SetusedAccounts = new Set<Id>();
For(Contact con : [Select Id, AccountID From Contact Where AccountId != null]) {
   SetusedAccounts.add(con.AccountId);
}
List<Account> lstAccount = [Select Id from Account Where ID Not IN:SetusedAccounts];
System.debug('Accounts Without Contact Are'+lstAccount);
Mark answer as best if it does help you.


Thanks,
Rahul