7

I use VS Code and use Uncrustify to format the apex code As per this article.

This was working fine for me until all of a sudden my SOQL lines are now automatically indented after the WHERE clause.

What is currently happening:

List<Account> liAccounts = [SELECT Id
                            FROM Account
                            WHERE ..... 
                               (8tabs)     OR ....
                                      (8tabs)      OR ....
                                             (8tabs)       OR ....];

Desired Behaviour:

List<Account> liAccounts = [SELECT Id
                            FROM Account
                            WHERE ..... 
                            OR ....
                            OR ....];

I have tried changing some settings in the config however I cannot seem to get this fixed. It is proving to be very frustrating and time consuming.

Has anyone experienced this same behaviour?

Do you know how I can fix this so I can achieve my desired behaviour?

10
  • 1
    I solved this temporarily by disabling the 'format onSave' and switching to use the VScode extension 'Aura Helper' to format the apex class with. I am still unsure as to whether or this could have been fixed by using uncrustify. I hope Salesforce releases a formatter for Apex in VSCode soon. – Z33dawg Oct 16 '19 at 14:30
  • 6
    Have you evaluated Prettier as an alternate solution? It's a little closer to a supported solution. – David Reed Jan 2 '20 at 20:09
  • 2
    @DavidReed - I have now!... indeed it does work better. thanks. Any idea how I can added custom rules, like changing list<account> to List<Account> or ID contactID to Id contactId etc? – Robs Jan 2 '20 at 21:10
  • 1
    @DavidReed - I don't really need to get Uncrustify to work now... please may I get my 50 points refunded? :-) – Robs Jan 2 '20 at 21:33
  • 2
    @Robs I am fairly sure I can't do that! – David Reed Jan 2 '20 at 22:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.