Activity Forums Salesforce® Discussions How to retrieve related List of Objects which exist in Salesforce?

  • Shubham

    Member
    August 21, 2017 at 10:15 am

    Hi Shaharyar

    Please Try This Query

    //

    Select Id,(Select id From Contacts),(select id from cases),(select id from opportunities) from Account

    //

    You may use different field according to your need

     

  • Shaharyar

    Member
    August 21, 2017 at 11:00 am

    Hello Shubham,

    Thanks for your answer but My question is different Suppose i don't know the name of related list which exist.Then how i can get the name of all related list.

     

    I have found this code while searching on net. But it is not working.

    Plese check it if u can make it correct:

    public class getRelatedList {

    public static map<string,string> getRelatedObjects(string Account){

    map<string,string> relatedObjectsMap = new map<string,string>();
    list<Schema.Childrelationship> relatedObjectsList = Schema.getGlobalDescribe().get(Account).getdescribe().getChildRelationships();
    for (Schema.Childrelationship relatedObject : relatedObjectsList) {
    if(relatedObject.getChildSObject().getDescribe().isUpdateable()
    &&
    relatedObject.getChildSObject().getDescribe().getKeyPrefix()!=null
    &&
    !relatedObject.getChildSObject().getDescribe().isCustomSetting()
    &&
    relatedObject.getChildSObject().getDescribe().isCreateable()
    )
    relatedObjectsMap.put(relatedObject.getChildSObject().getDescribe().getName(),relatedObject.getChildSObject().getDescribe().getLabel());
    }
    return relatedObjectsMap;
    }
    }

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos