2

I'm trying to get a list of all objects and the URLs that lead to their page in the Setup:

enter image description here

From the docs I'd expect the below to work but it returns:

"Expression of type Schema.DescribeSObjectResult has no member named urlDetail"

List < Schema.sObjectType > objectSchema = Schema.getGlobalDescribe().Values();

for (Schema.sObjectType obj: objectSchema) {
DescribeSObjectResult describe = obj.getDescribe();

System.debug(describe.urlDetail);

}
7
  • 1
    you are referencing the SOAP API which isn't always 1:1 with the Apex Describe; Furthermore, urlDetail is akin to URLFOR and is unrelated to the setup page
    – cropredy
    Commented Jun 20, 2016 at 15:10
  • 1
    it is because, urldetail is not a member of class DescribeSObjectResult class. Commented Jun 20, 2016 at 15:29
  • Schema.DescribeSObjectResult is a different thing than DescribeSObjectResult Commented Jun 20, 2016 at 16:01
  • No, the Schema. is optional. They are the same.
    – Adrian Larson
    Commented Jun 20, 2016 at 18:24
  • I'm still not quite sure how to do it and the answer below didn't work. I also can't see how Schema.DescribeSObject is different from DescribeSOBject. That seems crazy to me either it is of that class or it isn't. And if they are the same why the docs would say that it would work when it doesn't. Commented Jun 25, 2016 at 22:15

1 Answer 1

2

You can actually query EntityDefinition to get the information you want. However, at least in my sandbox, the value in the DetailUrl field is always just /{ID}. The Id value itself is just 000000000000000AAA. Not that useful. But, not to fear, you can use the DurableId to build it yourself.

The following works generically for me without issue:

public static String getSetupUrl(SObjectType schemaType)
{
    String developerName = String.valueOf(schemaType).replace('__c', '');
    EntityDefinition definition = [
        SELECT DurableId, DetailUrl FROM EntityDefinition
        WHERE DeveloperName = :developerName
    ];

    system.assertEquals('000000000000000AAA', definition.Id);
    system.assertEquals('/{ID}', definition.DetailUrl);

    return URL.getSalesforceBaseUrl().toExternalForm() +
        '/' + definition.DurableId;
}

Note

You can't use the standard ApexPages.StandardController.view() methodology for building the url because the id values are fubar. It just returns null.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .