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
justin_sfdcjustin_sfdc 

Change Data Type from Picklist to Text field

Hi, 

I want to get some suggestions on one of the issues I am having. 

 

I want to change the data type for one of the custom objects. Currently, the field is picklist and is being used in multiple apex classes and triggers. I need to change it to Text field. I have come up with two solutions so far but I am not sure if any of these is the best practice. Please correct me if I am missing anything.

1) First solution is to comment the codes where the field is being used and then change the dataType and again uncomment back the codes. With this process, when I have to deploy it to production, it might be a bigger risk as it is being used in multiple places.

2) Second solution that I could think of is; creating a new field with datatype 'Text', and copying the existing records to this new field. Then replacing this new field with old field in the Apex classes and triggers.

 

Please suggest me if there are any other solutions.

Also, please suggest how would I revert this whole process if something goes wrong (any suggestion except the refresh of the sandbox would be appreciated).

 

Thanks in Advance!

Justin.

Best Answer chosen by Admin (Salesforce Developers) 
Suresh RaghuramSuresh Raghuram

you should do the combination of both steps.

 

As you said you want to comment all the code where it has been used, do it then change the API name of that picklist field and create a text field with the same old name of the picklist field and copy the data from picklist to the text field and decomment and do all the necessary checks to let know every thing is going well.

By doing this you will have the old field and new filed , when you are very sure and no longer the picklist field necessary get rid of that.

 

 

If this answers your question make this as a solution and give kudos.

All Answers

Suresh RaghuramSuresh Raghuram

you should do the combination of both steps.

 

As you said you want to comment all the code where it has been used, do it then change the API name of that picklist field and create a text field with the same old name of the picklist field and copy the data from picklist to the text field and decomment and do all the necessary checks to let know every thing is going well.

By doing this you will have the old field and new filed , when you are very sure and no longer the picklist field necessary get rid of that.

 

 

If this answers your question make this as a solution and give kudos.

This was selected as the best answer
justin_sfdcjustin_sfdc

Thanks a lot!

Suresh RaghuramSuresh Raghuram
you also raised a issue with prod. after commenting out the code deploy all commented components of code to the prod and then do as i said in the before post once it is done decoment and deploy.

but make sure to have a list of where you are making the number of changes
justin_sfdcjustin_sfdc

Thanks for the tip! :)