10

I had to rename a class or two and I'm used to the Eclipse refactoring capabilities which update all references as part of the name change. In Salesforce the rename is not supported in the IDE (v 25), so the way to rename is to do it in SF (web) itself. The problem is that when I rename the class not all references are updated. After I did the rename I compiled, saw errors, fixed and repeated that until no more errors.

Afterwards, I thought a better workaround would be to create the new class in the IDE and copy the contents of the old class into it, fixing up any self references to get it to save w/o errors. Then do a find and replace in files in eclipse to update any *.cls, *.trigger, (and maybe *.page, *.component) files to use the new reference. Then save to the server and delete the old class. Next time, I may try that.

My questions are what is the best approach to refactoring Apex? Are there any tools or best practices to be more efficient and accurate? Thanks.

1
  • 2
    I've only done it the second way: make a new class, copy the old contents into it, and hunt down any references to be changed. Then delete the old one. Deleting or changing Apex components is not easy. Aug 24, 2012 at 19:08

2 Answers 2

5

I use the second method. After refactoring, I select the 'src' folder, use File Search/Replace and all the changes are made and saved to the server in one go.

1

I do it via your second way i.e. File search in eclipse, but instead of a new class. I mostly create a new method with required changes in the same class, after all the dependencies are updated I just delete the old method header and reuse the same old code with new one. Same applies to variables as well.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .