You need to sign in to do that
Don't have an account?
Get avaialble related lists for object
Hi,
how to get available related lists names for any object?
Thanks,
N.J
how to get available related lists names for any object?
Thanks,
N.J
You need to sign in to do that
Don't have an account?
https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_methods_system_sobject_describe.htm#apex_Schema_DescribeSObjectResult_getChildRelationships
Use parent to child soql query.
For more information. Check the below link.
http://www.salesforce.com/us/developer/docs/dbcom_soql_sosl/Content/sforce_api_calls_soql_relationships.htm
Schema.DescribeSObjectResult describeResult = Account.getSObjectType().getDescribe();
List<Schema.ChildRelationship> childRelationships = describeResult.getChildRelationships();
However, it should be noted that this will return ALL CHILDREN of the object, and there are many of these that are not "related lists" to the actual object in question. It is (unfortunatly) almost impossible to determine which ones are valid related lists (and certainly which are actually displayed on any page layouts).
The closest you might be able to get is to check if the relationship has a name (because the Related List children require a name) using something like
for(Schema.ChildRelationship thisChild : childRelationships)
{
if(thisChild.getRelationshipName() != null)
{
// do something like add it to your result list
}
}
but this WILL still return some relationships that are not related lists/valid for use in the related list visualforce tag (was that a lucky guess?! ;) )
I did the same way but facing issue with not valid ralationships.
Thats why wanted to check if anyone knows how to get the relatedlist names which are available to use on object.
Thanks,
N.J
Thinning out the list on Name got us pretty close. In the end, the requirement was revoked so we never polished it properly. You could possibly load the short list, and then quickly (and silently) spin through it in your controller trying to construct a dynamic related list component (which you subsequently just discard) and add all the non-exception throwing values into a list... but uggh, that sounds pretty gross!!