Here is the tricky way to covert your 15 digit ID value to 18 digit in salesforce.
Consider the below example,
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.
Consider the below example,
- String str = '0019000001O73UC';
- Id convertedId = str;
- 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