Tuesday, 3 December 2013

How to get key prefix of an Object in Salesforce.

We know there are two types of record-id are present in salesforce.

  • 15 digit -- Case Sensitive
  • 18 digit -- Case Insensitive
Only 3 digit of ids represent object type .


for example 

  • Account-- 001
  • Contact-- 003
  • Opportunities --006
  • Lead  --- 00Q
How will get these prefix dynamically, I mean by using apex code ?

Schema.DescribeSObjectResult r = CustomObject__c.sObjectType.getDescribe();
String keyPrefix = r.getKeyPrefix();
System.debug('Printing --'+keyPrefix );
It will print prefix of Custom Object id.

6 comments:

Unknown said...

Your information is really nice and very informative. Thanks for sharing this great article.

Salesforce Training

Asish Kumar Behera said...

Thank You christina jeni...

Fabian said...

Thank you, This is really handy!!

Asish Kumar Behera said...

Thanks @Fabian

Asish Kumar Behera said...

Thanks @Fabian

Unknown said...

That is very interesting; you are a very skilled blogger. I have shared your website in my social networks! A very nice guide. I will definitely follow these tips. Thank you for sharing such detailed article.

SalesForce online training