Salesforce Interview Questions & Answers Book is now available!

Grab Now

Release notes

Convert an 18-character Id value to a 15-character case-sensitive string - Spring '21

For some reason, if you ever want to convert an 18 digit record ID to a 15 digit ID it's easy now.

By Teja, ex-Salesforce engineer · Updated January 7, 2021 · 1 min read

For some reason, if you ever want to convert an 18 digit record ID to a 15 digit ID, starting spring 21 release you can use a method which is part of System.Id class and the name of the method is to15().

Here's a quick example.

String id_15_digit = '';
String id_18_digit = '';

//we need to convert it as the method to15() is available on ID class and not String class
Id converted_18_digit_id = id_18_digit;

//this is going to return true
System.assertEquals(converted_18_digit_id.to15(),id_15_digit);

Learn it by building it

Every course, every code repository, the discussion group and certificates of completion — one subscription.

Keep me in the loop!

Email me when a new episode is published (promise, I will not spam you)

You're signing up to receive emails from Salesforce Casts