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
sriram admin 3sriram admin 3 

Write an SOQL Query to fetch Account Records, where account records should filter based on Lookup field(Account)in contact object?

Can someone please help to write Query ?
Best Answer chosen by sriram admin 3
Suraj Tripathi 47Suraj Tripathi 47
Hi sriram,
please use below code to get account records based on lookup field 
 
list<contact> conList = [select id,AccountId from contact where accountId != null];

set<id> accIdSet = new set<id>();

if(!conList.IsEmpty()){
for(contact conObj:conList){
accIdSet.add(conObj.accountId);
}
}

list<Account> accList = [select id , name from Account where Id In:accIdSet];

 If you find your Solution then mark this as the best answer.

Thank you!

Regards,

Suraj Tripathi