How can do code alignment with Eclipse base Force.com IDE. Alignment shortcut key 'CTRL+SHIFT+F' is not working for Apex code.
If you mean formatting, then Ctrl + Shift + F . Save this answer.
You can use Ctrl + A to select the entire file, then use this shortcut to quickly fix all the indentation. You can also change how Eclipse handles indentation by going to Window > Preferences, then in the left panel, navigate to Java > Code Style > Formatter > Edit... > Indentation.
None of the suggestions so far work for me. Note that the Force IDE opens the Apex class in an Apex Editor. This editor does not appear in the list of contexts that you can associate with a key event. For example, this list contains such contexts as "editing in structured text", "editing in Java Source", etc.
The Apex Editor does not contribute a "Source" menu option to the right click menu. So there is no way to get to the formatting features.
I tried to open the apex class in the Java. Now the "Source" menu option appears the format option doesn't do anything. (Hence no key event will be able to do anything.)
The only thing I can get to work is this ...
Select file.... Open With... Other ... locate Java Editor. Once file is open ... select all text .. right click and select Source ... Correct Indentation .
This does not reformat but it does fix the indentation problem.
Someday I hope SFDC will make the code for the Force IDE open source. Then we, as a community, could build more developer-friendly tools.
Apex classes and triggers use a different editor than Java. The auto formatter (or code alignment) does not work with Apex Code (or the Apex Code Editor). I couldn't get CTRL-SHIFT+F to work in the most recent version of Eclipse with the Force.com IDE, either. I believe this is because the auto formatter is designed to work with Java only.
However, if you switch to the Java perspective and open your Apex class with the Java Editor, CTRL+I does correct indentation properly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With