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!!!

2 comments:

  1. It is not working. Do you know any other method.

    ReplyDelete
    Replies
    1. String 'a' should have valid record id.

      Delete