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
.
urlDetail
is akin toURLFOR
and is unrelated to the setup pageSchema.
is optional. They are the same.