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
Ranjith YMRanjith YM 

count number of account without lead

I can get the count of leads which has an account based on ConvertedAccountId/ConvertedContactId but I totally stuck to get the count of an Account which has no corresponding lead.

Can someone please help me with this... thanks ini advance

Deepak_KumarDeepak_Kumar
Hi Ranjith, Please try the following approach:
List<Lead> leads = new List<Lead>();
leads= [SELECT ConvertedAccountId FROM Lead WHERE ConvertedAccountId !=null];
Set<Id> ids = new Set<Id>();
for(Lead lead:leads){
    ids.add(lead.ConvertedAccountId);
}
List<Account> accounts = new List<Account>();
accounts= [SELECT Name FROM Account WHERE Id NOT IN :ids];
System.debug(accounts.size());

Please also mark this solve if this helps you.
Thanks.
Deepak