You need to sign in to do that
Don't have an account?
Venki123
Query Account Record without Child Object
Hi All,
I need help. I have 15 child object in the Account Object. I want to query a Account record which is not having any child object. Is there any easiest way to do it. I have lots of account records. Can you please suggest a fastest way to query the Account record which is not having any child object.
Thanks for your help in advance,
Venkatesh
I need help. I have 15 child object in the Account Object. I want to query a Account record which is not having any child object. Is there any easiest way to do it. I have lots of account records. Can you please suggest a fastest way to query the Account record which is not having any child object.
Thanks for your help in advance,
Venkatesh
As long as you want to know the Parent without it's child object, you will have to query on all the childs to know that parent is attached to them or not.
One thing as per my knowledge, you can create a custom field on Account object and update it through trigger whenever child object records will be create on the Account records. So if you want Account without child object, you can query on Accounts where that custom field is blank/equals to zero.
Thanks,
Pratik
Let me show you an example with 10 child objects of account,
At line 5 you get all account records that have 0 entry in those 10 childs. This SOQL use is 5 statements for 10 childs. You can use this approach for 15 objects and use 8 statements. You may also go for what Pratik suggested. In fact that is more efficient if you have the freedom to implement all those fields and triggers at this stage. To learn more about SOQL joins refer this,
https://developer.salesforce.com/page/A_Deeper_look_at_SOQL_and_Relationship_Queries_on_Force.com
-Akram