How to convert String to record Id in Salesforce?

String recordId = '01I20000000VyKGAAN';
Id newId = Id.valueOf(recordId);

Note: Here String recordId should be a valid record id. Salesforce Id is system generated Id and we cannot generate it.

Leave a Reply