Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to find a way to get the "Id" for a custom object's setup page. So I'm NOT trying get a record Id. I'm working on a custom visualforce page and I'm setting up a link so that when the user clicks it, it'll direct them to the object's setup page. I've included a picture below to show what I'm am trying to get.


Does anyone know of a way to query for that Id through Apex? I tried using the describe methods, but had no luck...

Any help/tips would be greatly appreciated!

  • Ryan
share|improve this question
up vote 12 down vote accepted

You can do this using the Salesforce Tooling API library from Apex or just the following code by itself:

//choose your object name (without suffix!)
String objectName = 'Work';

String query = 'SELECT Id From CustomObject Where DeveloperName = \'' + objectName + '\'';
String endpoint = Url.getSalesforceBaseUrl().toExternalForm();
endpoint += '/services/data/v29.0/tooling/query/?q=';
endpoint += EncodingUtil.urlEncode(query, 'UTF-8');

HttpRequest request = new HttpRequest();
request.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionId());

HttpResponse response = new Http().send(request);
Id customObjectId = response.getBody().substringAfter('"Id":"').substringBefore('"');

//eg '01Id0000001BSeoEAG'

Which will give you something like:


parsed from the raw response:

    "size": 1,
    "totalSize": 1,
    "done": true,
        "attributes": {
            "type": "CustomObject",
            "url": "/services/data/v29.0/tooling/sobjects/CustomObject/01Id0000001BSeoEAG"
        "Id": "01Id0000001BSeoEAG"
share|improve this answer
Thank you, that was exactly what I was looking for. I have another question. I had to set a remote site (the site I used was the one given to me by Url.getSalesforceBaseUrl() ) manually. Do you know a way to set a remote site dynamically or a way to find an even more generic web address that I could set as the remote site? I'm looking for something that'll work across different instances and not require the user to manually set the remote site for every different instance. – user7702 Apr 7 '14 at 21:30
@user7702 Maybe in lieu of a callout you can get creative with PageReference.getContent() and a relative URL which doesn't require a Remote Site Setting. – bigassforce Apr 7 '14 at 22:17

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.