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;
}
}