8

I have a custom object and I would like to know which all other objects have look up relations to this one? There are many objects available and I cannot go into each and identify which would have look up.

Is there a way to identify this? In this way, I also would know what objects have relations with what other objects in SF.

11

You could get this with apex describe methods:

for ( Schema.ChildRelationship scr : Account.sObjectType.getDescribe().getchildRelationships() ){
    system.debug('');
    system.debug('**** Child SObject         **** ' + scr.getChildSObject());
    system.debug('     Field                 **** ' + scr.getField());
    system.debug('     Relationship Name     **** ' + scr.getRelationshipName());
    system.debug('     Cascade Delete        **** ' + scr.isCascadeDelete());
    system.debug('     Deprecated and Hidden **** ' + scr.isDeprecatedAndHidden());
    system.debug('     Restricted Delete     **** ' + scr.isRestrictedDelete());
}

Or if you want a visualization of the object relations, the schema builder is a nice tool.

3
  • Yup that's what I use every time. Might be worth debugging some of the key methods individually such as getChildSObject, etc. Not that it's not in the documentation, but newbies can't be trusted to look at that!
    – Adrian Larson
    Jul 11 '16 at 2:07
  • @AdrianLarson One can use workbench to easily figure this or an appexchange solution Jul 11 '16 at 2:11
  • 1
    I prefer Execute Anonymous but the votes will sort that out. More succinct syntax: for(ChildRelationship relationship : SObjectType.Account.getChildRelationships())
    – Adrian Larson
    Jul 11 '16 at 4:50
5

There are couple of tools thats very helpful

1.Workbench

You can see the Childrelationships to see all the all the objects for which the object is looked upto

enter image description here

2.Appexchange app named Schema Surfer

This app has logical arrangement of your metadata to help you figure all child objects

3

You can also use Etherios EasyDescribe - Free MetaData Viewer/Extractor from AppExchange which is shown below. You can also export the result to excel format.enter image description here

And also it has many other features.

1

I assume that you need this info for your use and do not need it in apex.

if that is true then are two MORE easy ways to get it.

A)Use eclipse (or any IDE)and find in files.

Here are steps:

1) Down load all your metadata on local machine with eclipse https://developer.salesforce.com/docs/atlas.en-us.eclipse.meta/eclipse/ide_getting_started.htm

2) Then go to search -> find in files

3) enter the object name for which you want to search all relationships and add filter to search only objects files.

4) This will give you result all objects that have

B)Use Schema builder.
1) Select auto layout
2) Select the objects in question
2) follow the line to understand the relationships

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.