How can I rename my Apex Class name in Salesforce

Janne picture Janne · Jun 26, 2018 · Viewed 7.5k times · Source

How can i rename my Apex class?

For example if I want to change the name of my apex class from ABC to ABC123, how can I do that?

Answer

martin picture martin · Jun 27, 2018

If you wanted to do it through a metadata deployment, your only option would be to delete the old class and create a new one.

In the ui (Setup > Develop > Apex Classes), you can change the class name, but it won't change any of the references, so if you don't manually change all references to the class, you might start getting errors that say:

Dependent class is invalid and needs recompilation

Renaming a class in the ui will associate a different name with the same salesforce id for the class, so there is a subtle difference between that and deleting and creating a new class.