I am trying to use forcetk
and I want to know if there is a simple way to:
- Get all object prefixes for all objects present in org
OR
- Based on an 15 or 18 digit Id get which object does it belong to
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