If yow will try to typecast String to Id Like- Id myId = Id.valueOf('Id'); // it will not work and give exception: System.StringException: Invalid id: Id We cannot generate SalesforceId using this method because Salesforce Id is system generated Id and it cannot be generated by us.
If you have valid id then it will work -
Id myId = Id.valueOf('001xa000003DIlo'); //this will typecast
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
String a = 'adfh123edrftghu789';
Id i = Id.valueOf(a);
Regards,
Magulan D
Salesforce.com certified Force.com Developer.
SFDC Blog
SFDC Site
If this post is your solution, kindly mark this as the solution.
If yow will try to typecast String to Id Like-
Id myId = Id.valueOf('Id'); // it will not work and give exception: System.StringException: Invalid id: Id
We cannot generate SalesforceId using this method because Salesforce Id is system generated Id and it cannot be generated
by us.
If you have valid id then it will work -
Id myId = Id.valueOf('001xa000003DIlo'); //this will typecast
I hope you find the above solution helpful. If it does, please mark as Best
Answer to help others too.
Thanks,
Ajay Dubedi