Copy contents of a field to a picklist in an Object

picklist

I have a requirement where I needed to convert a field in a particular object from a formula returning a number to a picklist. Since directly changing the data type would result in loss of data, it was decided to create a new picklist field corresponding to the existing number field.

I created the picklist field and add it to the relevant edit object VisualForce page layout but now I need to copy the corresponding data from the old number field. I'm not sure what is the best way to achieve this.

Also, the new picklist field will come into play only when editing the object. The initial value of the picklist will always come from the old formula field.

Any help will be appreciated.

Best Answer

You can create the new picklist, but you still need to copy all the values over. There's several ways to do this, but perhaps the easiest is a quick import and export. Use the Apex Data Loader, Workbench, etc to query all Id values and the old formula values, then use an update operation to map the csv you get from the export to the new field. Obviously, you'll do this after you create the new field.