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
Shank_dhelShank_dhel 

want to get child object for an object which has only master detail relationship

hi ,

i'm getting objects from schema

based on the user selection of object ,it has to display all the child objects of the selected master object which has master detail relationship .

 

i'm using getChildRelationships() function to get the child relationship

but how to restrict it to get only childs with master detail relaationship

 

thanks in advance

Best Answer chosen by Admin (Salesforce Developers) 
Gunners_23Gunners_23

There's a workaround for this but bit kludgy

 

Schema.DescribeSObjectResult R = Account.SObjectType.getDescribe();  // Get the info regarding object


List<Schema.ChildRelationship> C = R.getChildRelationships();         // Get all the child relationships

 

Now that you got the child relationships, you can iterate the list and check for "isCascadeDelete()" method

 

which returns the boolean value. Since value for MD will be true, you can consider

 

those relationships as master detail

All Answers

Gunners_23Gunners_23

There's a workaround for this but bit kludgy

 

Schema.DescribeSObjectResult R = Account.SObjectType.getDescribe();  // Get the info regarding object


List<Schema.ChildRelationship> C = R.getChildRelationships();         // Get all the child relationships

 

Now that you got the child relationships, you can iterate the list and check for "isCascadeDelete()" method

 

which returns the boolean value. Since value for MD will be true, you can consider

 

those relationships as master detail

This was selected as the best answer
Shank_dhelShank_dhel

Thanks a lot  Gunners

 

 

u saved my day ...

 

coffee is on me... :)