+ Start a Discussion
SoleesSolees 

What is the equivalent of this? in Javascript

Hi friends, how can i do this:

Schema.SObjectType.Account.getKeyPrefix();

 

but using javascript or sfoce ajax ?

 

thanxs

Rahul SharmaRahul Sharma

Hey,

 

 

Try using code below and check if it helps:

DescribeSObjectResult describeSObjectResult = sforce.connection.describeSObject("Account");
alert('What is the prefix : ' + describeSObjectResult.getKeyPrefix());

 Refer this link for more help.

Anirudh SinghAnirudh Singh
If you want to access the keyprefix in Javascript, you will need to use ajax toolkit, for that incude the following in your page:
<script src="../../soap/ajax/34.0/connection.js" type="text/javascript"></script>

And in the javascript, you need to use:
sforce.connection.sessionId="{!$Api.Session_ID}";
var result=sforce.connection.describeSObjects(["objectAPIName"]);
var objectPrefix=result[0].keyPrefix;
console.log(objectPrefix);