3

I find an object I need in Setup => Create => Objects. I want to get a list of this objects or create a new one.

I know, that if I have an existing object, I take first three chars and I'm fine. Here, I don't know this prefix.

How can I get it without Eclipse IDE? Like, I'm a regular user and I want to create this type of object. No tab for this object.

0

3 Answers 3

3

The Workbench tool will allow you to retrieve the key prefix of any standard and custom object: https://workbench.developerforce.com/login.php

Not only the key prefix, but other information as well, like the fields, relationships and so on. Just login, describe your object and you are good to go!

18

As a regular user, the only way would be to either attempt to create a record from a related object then look at the URL to get the prefix or view an existing record and look at the url.

If the user has access to the dev console you can debug this line of code:

system.debug(logginglevel.error,OBJECTAPINAME.sobjecttype.getDescribe().getKeyPrefix());

Otherwise with your given parameters it would not be possible.

If the Sandbox is a FULL sandbox the key prefix should be the same as it is in Production

6

After a lot of snooping around (and thanks to the other answers in this thread) I thought I'd come back here and post some code for retrieving the SObject name (not the label!) and the corresponding prefix:

for(schema.SObjectType s : Schema.getGlobalDescribe().Values()){
    if(s.getDescribe().getKeyPrefix() != null){
        system.debug(s.getDescribe().getName() + ': ' + s.getDescribe().getKeyPrefix());
    }
}

This will give you a list of all your objects and their key prefixes in the debug log. You can run this in the workbench (under utilities > Apex Execute) to get it to output.

Hope this helps other people doing the same search as me!

8
  • Note that this approach will not give you the key prefix for every objects. Only those returned by the global describe. There are many objects which are not.
    – Adrian Larson
    Oct 18, 2017 at 20:32
  • This is true - there were a bunch of objects that came back with a null prefix, so I should have specified that this approach will give you the key prefix for MOST standard objects and (I assume) ALL of your custom ones. Thanks for clarifying Adrian. Oct 19, 2017 at 21:48
  • I think you missed my point. There are many object types which are not returned by the method Schema.getGlobalDescribe().
    – Adrian Larson
    Oct 19, 2017 at 21:49
  • Oh, so you're saying that there are objects which won't even appear when you take out the filter for null key prefixes? What kind of objects? (Am I right in saying that all custom objects should be returned? That's usually the use case for me when I'm trying to get the key prefix) Oct 19, 2017 at 21:56
  • 1
    fishofprey.com/2011/09/…
    – Adrian Larson
    Oct 19, 2017 at 21:57

You must log in to answer this question.

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