How to convert String to Id?

Sample Code:

String a = 'adfh123edrftghu789';
Id i = Id.valueOf(a);

here String 'a' should be a valid record id. We cannot generate Salesforce Id using this method because Salesforce Id is system generated Id and it cannot be generated by us.


Cheers!!!

3 comments: