How to convert 15 to 18 digit Id using Apex in Salesforce?

How to convert 15 to 18 digit Id using Apex in Salesforce?

Similar to String data type, we have Id data type in Salesforce Apex. So, using Id data type, we can convert the 15 digit Id to 18 digit Id using Apex.

Sample Code:

String fifteenDigit = '0SO90000000PBDu';
Id eighteenDigit = fifteenDigit;        
System.debug( '15 Digit Id is ' + fifteenDigit );
System.debug( '18 Digit Id is ' + eighteenDigit );

Output:

Leave a Reply