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.

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);