How to Convert 18 Digit Id to 15 Digit Id using Apex Class?

Example1:
convert the Id to a String and using substring(startIndex, endIndex) its possible to convert from 18 digit Id to 15 Digit Id.
String AccountId = String.valueOf(Account.Id).substring(0, 15);

Example2:
To convert it to 15 digits to 18 digits then you can simply set it to an Id type variable:

Id someId = ‘001J000001eun1Q’;
Which will automatically convert it for you:

system.debug(someId); // 001J000001eun1QIAQ
Then you can simply call the getSObjectType() method on the Id variable which will return the object name:

Schema.SObjectType objectType = someId.getSObjectType();
system.debug(objectType); // Account

Salesforce ID Converter
Converting 15 digit to 18 digit Salesforce ID
https://help.magentrix.com/aspx/ConvertSFID

What is the difference between a 15 digit and a 18 digit Salesforce ID?
A 15 digit Salesforce ID is case sensitive. Ex:  00570000001ZwTi and 00570000001ZWTI are different.
A 18 digit Salesforce ID is case in-sensitive. Ex:  00570000001ZwTiXYZ and 00570000001ZWTIXYZ are same.

(36)

Written by 

I am Sakthivel Madesh, a certified Salesforce Developer & Administrator working on Salesforce Technology since 2011. I am currently working in IBM Austraila as Sr. Salesforce Developer. I have worked on multiple technologies Like PHP, Java, Salesforce, I am very passionate about Salesforce and to earn 12x Salesforce Certification. I love Trailhead for learning Salesforce Skill and Become a Trailhead Ranger too. I Love to Learn & Share my Salesforce knowledge to Salesforce Learners/Beginner using My Blog and Salesforce Community.

Leave a Reply