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
abhishek satputeabhishek satpute 

what will be the soql query to find the no child account records related to specific account record in account object

Best Answer chosen by abhishek satpute
AbhishekAbhishek (Salesforce Developers) 
May I request you please check the Salesforce documentation on  "SOQL Relationship Queries" check the below link?

https://developer.salesforce.com/blogs/developer-relations/2013/05/basic-soql-relationship-queries.html   (https://developer.salesforce.com/blogs/developer-relations/2013/05/basic-soql-relationship-queries.html  )


Basic Examples of SOQL RELATIONSHIPS:
Child > Parent (Standard Object)


Selectid,Account.Name,Account.Phone,Account.industry,Account.Type,Account.Rating,Account.website,Account.Ownership,Account.AnnualRevenue,Account.NumberOfEmployees,Account.CleanStatus from Contact
Child >Parent(Custom Object)


Selectid,COLLEGE__r.Name,COLLEGE__r.Contact__c,COLLEGE__r.Count__c,COLLEGE__r.Highest_Marks__c,COLLEGE__r.Address__cfrom Studnt__c

Parent >Child(Standard object)
select Name, Industry, (select AssistantName, Email from contacts)from ACCOUNT


Parent >Child (Custom Object)
1select id,Name,(select Studnt__c.name__c from Studnts__r) from College__C


For further reference check this,

https://developer.salesforce.com/forums/?id=906F00000009BgeIAE


If it helps you and closes your query by marking it as solved so that it can help others in the future.

Thanks.

All Answers

AbhishekAbhishek (Salesforce Developers) 
May I request you please check the Salesforce documentation on  "SOQL Relationship Queries" check the below link?

https://developer.salesforce.com/blogs/developer-relations/2013/05/basic-soql-relationship-queries.html   (https://developer.salesforce.com/blogs/developer-relations/2013/05/basic-soql-relationship-queries.html  )


Basic Examples of SOQL RELATIONSHIPS:
Child > Parent (Standard Object)


Selectid,Account.Name,Account.Phone,Account.industry,Account.Type,Account.Rating,Account.website,Account.Ownership,Account.AnnualRevenue,Account.NumberOfEmployees,Account.CleanStatus from Contact
Child >Parent(Custom Object)


Selectid,COLLEGE__r.Name,COLLEGE__r.Contact__c,COLLEGE__r.Count__c,COLLEGE__r.Highest_Marks__c,COLLEGE__r.Address__cfrom Studnt__c

Parent >Child(Standard object)
select Name, Industry, (select AssistantName, Email from contacts)from ACCOUNT


Parent >Child (Custom Object)
1select id,Name,(select Studnt__c.name__c from Studnts__r) from College__C


For further reference check this,

https://developer.salesforce.com/forums/?id=906F00000009BgeIAE


If it helps you and closes your query by marking it as solved so that it can help others in the future.

Thanks.
This was selected as the best answer
SwethaSwetha (Salesforce Developers) 
HI Abhishek,
The approach in https://salesforce.stackexchange.com/questions/36690/soql-count-number-of-child-records should help here:
select parentid,count(id) from Account where parentid='0016F00003o9Hti' group by ParentId

In my org, parent account with Id 0016F00003o9Hti has 3 child accounts and it is returned as result.

Hope this helps you. Please mark this answer as best so that others facing the same issue will find this information useful. Thank you
Malika Pathak 9Malika Pathak 9

Hi Abhishek,

Please find the solution

what will be the soql query to find the no child account records related to specific account record in account object

public class demoquestion {
public static void disp(){
list<contact> conList=[select lastname,accountid from contact where accountid!=null];
list<opportunity> oppList=[select name,accountid from opportunity where accountid!=null];
set<id> sid= new set<id>();
for(contact con:conList){
sid.add(con.accountid);
}
set<id> sid1=new set<id>();
for(opportunity opp:oppList){
sid1.add(opp.accountid);
}
list<account> accList=[select name from account where id NOT IN: sid and id NOT IN: sid1];
SYSTEM.DEBUG('ACCOUNTLIST==>> '+accList);
}
}
 

If you find this solution is helpful for you please mark best answer

Mosh HamedaniMosh Hamedani
Image Restoration Services is an all rounder to convert your image into a sensational photograph. Images are gateways to the past and ITS, understands and treasures your moments for you with its professional Image Restoration Service.