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!!!
It is not working. Do you know any other method.
String 'a' should have valid record id.
Great Working:) (y)
String a = 'adfh123edrftghu789';
Id i = (Id) a;