3

I am trying to use forcetk and I want to know if there is a simple way to:

  1. Get all object prefixes for all objects present in org

OR

  1. Based on an 15 or 18 digit Id get which object does it belong to
0

1 Answer 1

3

You can use describeGlobal to get all of the object prefixes and then put them in a map:

var prefixToName = {};
client.describeGlobal(function(response){
    for (var i = 0; i < response.sobjects.length; i++) {
        var sobject = response.sobjects[i];
        if (sobject.keyPrefix) {
            prefixToName[sobject.keyPrefix] = sobject.name;
        }
    }
});

Then

var accountId = '0015000000VALE3';
console.log(accountId + ' has sobject type ' + prefixToName[accountId.substring(0,3)]);

Will give you

0015000000VALE3 has sobject type Account
3
  • Was hoping for an answer from you Pat, thanks for same :) I checked this out. Do we have a provision to get all fields for an object as well in forcetk? Thanks in advance
    – SEuser
    Commented Feb 29, 2016 at 22:13
  • Just checked, I think I need to use normal describe for object "forcetk.Client.prototype.describe" which can help me out. I will try for same.
    – SEuser
    Commented Feb 29, 2016 at 22:20
  • Yes - use the per-object describe method to get all the fields.
    – metadaddy
    Commented Mar 1, 2016 at 7:02

You must log in to answer this question.

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