Proper/Safe Way to Link to Salesforce Object

What is the proper/safe way to get/generate links for Salesforce objects retrieved through the REST API?

For instance, we have a tool living in another application that allows users to query for Salesforce content objects from the context of this other application and directly embed a link (just eases the process of linking to Salesforce content). At the moment, I am relying on the ID and the Salesforce URL (e.g., https://mysalesforceinstance.salesforce.com/|sobjectId|) as the URL that is embedded. Ideally, for content, we would link to the version page instead (e.g., https://mysalesforinstance.salesforce.com/sfc/#version/|sobjectID|). Is there a way to safely generate/retrieve this URL with the rest API? Or can I simply assume this URL will exist for all content objects?

I have seen in the past APIs that return a list of “resources” (e.g, URLs for all CRUD operations on the object) alongside an object, but I haven’t seen anything like this in the documentation.

Answer

I know your question is about the REST API, but with the SOAP Partner API you can use DescribeSObjectResult to get the urlDetail, urlEdit, and urlNew. With these you can build up the correct URL by substituting the {ID} value.

It looks like there are equivalent fields available via the REST API. I say “looks like” as there is something off about that documentation. It looks more like the SOAP API docs than the REST API.

If you do an SObject Describe via the REST API you can get the “urls” in the response. Like the SOAP API, you can substitute the {ID} with your value.

curl https://na1.salesforce.com/services/data/v20.0/sobjects/Account/describe/ -H   
     "Authorization: Bearer access_token" -H "X-PrettyPrint:1"

Output

{
    "name" : "Account",
    "fields" :
    [
        ...
    ],
    "updateable" : true,
    "label" : "Account",
    ...
    "urls" :
    {
        "uiEditTemplate" : "https://na1.salesforce.com/{ID}/e",
        "sobject" : "/services/data/v20.0/sobjects/Account",
        "uiDetailTemplate" : "https://na1.soma.salesforce.com/{ID}",
        "describe" : "/services/data/v20.0/sobjects/Account/describe",
        "rowTemplate" : "/services/data/v20.0/sobjects/Account/{ID}",
        "uiNewRecord" : "https://na1.salesforce.com/001/e"
    },
    ...
}

Attribution
Source : Link , Question Author : user7266 , Answer Author : Daniel Ballinger

Leave a Comment