function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
cloud21cloud21 

How to convert string to id

 

 below are the code

public static final string PICKLIST_SELECT = 'Select';

 

new selectOption(PICKLIST_SELECT,PICKLIST_SELECT)

 

 how to convert PICKLIST_SELECT in id

 

MagulanDuraipandianMagulanDuraipandian

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.

SANJUKTA BASAK 3SANJUKTA BASAK 3
@Magulan - This is an absolutely wrong approach that you have posted!
Ajay K DubediAjay K Dubedi
Hi,

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