Wednesday 27 May 2015

How to Convert Salesforce 15 digit ID to 18 digit ID in Apex

          Here is the tricky way to covert your 15 digit ID value to 18 digit in salesforce.

Consider the below example,

  1. String str = '0019000001O73UC';
  2. Id convertedId = str;
  3. System.debug('Converted ID value'+convertedId);

You can just assign your 15 character string value to the ID datatype. It will automatically convert this as 18 Digit.

Note: This one only applicable for Salesforce Id's not for other id such as External Id. If you try to assign any other values to Id data type, then you will receive an System.StringException: Invalid id Exception.

No comments:

Post a Comment

Activities: Assign Tasks to a Queue Salesforce Lightning

Salesforce announced to assign Tasks to a Queue beginning from Spring'20 release. How does it work? In Setup, enter Queues in th...