0% found this document useful (0 votes)
5 views4 pages

Salesforce Child Relationship Querying

The document contains code that retrieves child relationships of a Salesforce object and constructs subqueries for querying related records. It filters out specific relationship names and builds a query string for each valid child relationship, executing the queries to fetch parent records. The results are then processed to extract child records associated with each parent record.

Uploaded by

Ashutosh Agrawal
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views4 pages

Salesforce Child Relationship Querying

The document contains code that retrieves child relationships of a Salesforce object and constructs subqueries for querying related records. It filters out specific relationship names and builds a query string for each valid child relationship, executing the queries to fetch parent records. The results are then processed to extract child records associated with each parent record.

Uploaded by

Ashutosh Agrawal
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd

/*childObjectsRelationshipList = [Link]().getDescribe().

getChildRelationships();

for([Link] childRelation : childObjectsRelationshipList){

parentField = [Link]();

if([Link]() != null

&& ![Link]().contains('Event')

&& ![Link]().contains('WorkOrder')

&& ![Link]().contains('Histories')

&& ![Link]().contains('Shares')

&& ![Link]().contains('ActionPlans')

&& ![Link]().contains('Change')

//&& ![Link]().contains('Context')

//&& ![Link]().contains('Record')

){

String childObjName = [Link]([Link]());

//[Link]('childObject => '+childObj);

//[Link]('child relation name=> '+[Link]());

childObjDescribe = [Link](childObjName).getdescribe();

if([Link]() ){

[Link]([Link](),[Link]());

[Link]([Link](),parentField);

//[Link]('cObjectsMap=> '+cObjectsMap);

for(String key : [Link]()){


//[Link]('childObjectMap key=> '+key);

String subQuery = '(SELECT Id,'+ [Link](key) +' FROM '+ key+')';

if([Link]()==0){

[Link](1,new List<String>());

[Link]([Link]()).add(subQuery);

else if([Link]([Link]()).size()<20){

[Link]([Link]()).add(subQuery);

else{

[Link]([Link]()+1,new List<String>());

[Link]('queryStringMap=> '+queryStringMap);

for(Integer count : [Link]()){

//[Link]('Count value=> '+count);

query = [Link]([Link](count),',')+[Link](',');

query = 'SELECT ID,' + query +' FROM ' +selectedObject+ ' WHERE ID IN: recordIds';

[Link]('final query=> '+query);

parentRecordsList = [Link](query);

[Link](count,parentRecordsList);

//[Link]('parent records map=> '+parentRecordsMap);

query='';

for(sObject[] parentsList:[Link]()){
for(SObject parentObj:parentsList){

for(String cRelation: [Link]()){

//[Link]('cRelation=> '+cRelation);

[Link](cRelation, (List<SObject>)[Link](cRelation));

//[Link]('ChildRecords=> '+[Link]());

for(SObject[] childs:[Link]()){

if(childs == Null)

continue;

for(SObject child:childs){

[Link]('ChildRecords after removing null=> '+[Link]());

[Link]('child=> '+child);

[Link]('parent id field value=>> '+[Link](parentField));

/*for(SObject child: [Link]()){

[Link]('child=> '+child);

//Object pid = (Object)[Link](cRelation).get('Name');

//SObject pid =
(SObject)[Link](parentField);//.get([Link](parentField));
//ID pid = (ID)[Link](parentField);

Object pid = (Object)[Link](parentField);

[Link]('parent id======>> '+pid);

}*/

You might also like