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
Akshay GuptaAkshay Gupta 

How to query child record for multiple parent type

Hi Guys,
For my req is, task(custom vf page) can be created from related list of two custom object say A and B.
when a task is created a child object C also get created either A or B based on the related list of object from where the new task is created.
when task is edited it should query records of object C based on task if related to A or B
I want to query child object C dynamically in one query based on type of parent.

 
Vasani ParthVasani Parth
There are 2 scenarios:

In each specified relationship, no more than five levels can be specified in a child-to-parentrelationship. For example, Contact.Account.Owner.FirstName (three levels).
Example: SELECT OpportunityLineItem.Opportunity.Name, OpportunityLineItem.Opportunity.Owner.Name, Quantity 
FROM OpportunityLineItem
Only one level of parent-to-child relationship can be specified in a query. For example, if the FROM clause specifies Account, the SELECT clause can only specify the Contact or other objects at that level. It could not specify a child object of Contact.
Example: SELECT Account_Code__c, (SELECT Amount,IsClosed FROM Opportunities) FROM Account
Reference: Understanding relationships in SOQL. (https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/)