How to format Salesforce Codes in the best way possible

The first thing they are presented with is how the code was written, which should provide subtle clues as to the original intent, allowing the reader to easily read and understand code that is foreign to them, especially if they have no idea what exactly a piece of code does. It is a rare occurrence to have complete and up-to-date documentation.

The Best Way to Make Your Code “Prettier”

You can be sure that Prettier will keep your code looking nice and readable, regardless of whether you’re writing Lightning Web Components or Apex backends. Use VS Code, the Prettier Extension can be found on the extension’s marketplace, and we can install Prettier very easily.
The first step towards formatting Apex with Prettier is to install an extension, which is easy, just follow the command below (make sure you have node installed).

1) npm install --save-dev --save-exact prettier prettier-plugin-apex

It rewrites your code in a way that it thinks is best after stripping all styling from it. The code can even be saved automatically every time, which is great as it makes writing our code feel more natural.

In order to conform to a style standard, Prettier does the legwork. What does it consider “Good”? Let’s find out.

Prettier helps keep a consistent style in several ways:

⇰ Adds semicolons;
⇰ Commas at the end of sentences;
⇰ Using quotations consistently;
⇰ Maintain consistent indentation spacing (usually four or two spaces/tabs);
⇰ Function/method declarations and parameters should be spaced consistently;
⇰ Ensure that bracketed items are spaced consistently.

Even though Prettier is great, computers are dumb and need explicit instructions, while our code is full of context and implicit information. While Prettier does a wonderful job, we can help take it to the next level by tweaking our own coding style just a tiny bit.

 

 

To receive the latest news and posts directly in your inbox, subscribe to Fidizzi

Subscribe

* indicates required
cropped-medium-3

Salesforce Admin Group 2022

On October 6, 2022, Fidizzi hosted Salesforce Admin Group 2022, we welcomed Andy Utkan, from Salesforce Break, and Sergio Cardoso from Fidizzi. It was another excellent participation of the Salesforce

 4,614 total views

Read More »

The Golden Hoodie Tradition

  (Looks like the star: Tanuki is also a fan of the Golden hoodie) Gifting a Golden Hoodie to inspiring Trailblazers at a Salesforce event is our way of saying

 4,315 total views

Read More »