[SalesForce] How to change a field type and deploy when field is referenced in code

I have a custom field on the user object that I need to change from Field Type Text to Field Type Multi-Picklist.

The field is referenced more than 500 times in 25 Classes, Triggers and VisualForce Pages. To commit the change, I am about to fo the following:

  1. Comment all references of the field in classes, triggers and pages (sandbox)
  2. Change the field type
  3. Modify test classes to adjust to commented lines
  4. Deploy change to production environment
  5. Uncomment all reference to field in classes, triggers, and pages (sandbox)
  6. Revert changes done to test classes
  7. Deploy again to production

I am hoping there is a better way to do this. Any suggestions would be greatly appreciated.

Best Answer

These are always tough.. If it's that often referenced I often go for a new field instead of field type change. That way you will suffer less from references and dependencies between classes, as you don't have to do a 'big bang' scenario but have the option to move over gradually if things don't go that smoothly. It might seem relatively easy doing this on a sandbox, but wait until e.g. your test coverage drops because of the commented out fields..

Main drawback is that all list views, reports, etc need to be updated as well since it will be a different field. And you will need a (simple) data migration.

Also, did you check for references in the rest of the org, e.g. formula fields, validation rules, workflow rules & field updates?

To get the complete picture, I often do a download of the complete metadata to Eclipse (refresh the metadata and check all the checkboxes to get all the metadata) and use CTRL+H to search across the entire project. That will also give you references in workflow, formulas, list views, reports etc. It also gives you the option to search and replace and save directly to the org from which you fetched the data (e.g. production).