Menu
subscribe our youtube channel popup

Clean code in Salesforce

We spend more time reading our code than writing it. So, doesn’t it make sense that our code is clean, precise, and easy to read? In this session, we discuss how to take quickly written code and apply best practices to refactor it. Join us to learn how to write Clean Apex Code in Salesforce. We will take a messy piece of code step by step and refactor it.

Why do we need Clean code in Salesforce?

Why do we need clean code? Destructive code works, too! Don’t fix what is not broken. Let’s understand why we need it in Salesforce.

Best practices to write clean code in Salesforce

Follow the best practices below to write good code in Salesforce.

  • Easy to understand by other developers: readable by developers other than the one who developed it.
  • Easy to maintain: lower chances of accidentally introducing bugs.
  • Modified without fear of breaking anything: Many Salesforce developers take great pride in making the code compact – trying to do multiple things on one line – which might be impressive but makes the code much harder to read and understand.

Rules to write Clean Code

  • Keep your methods short.
  • Don’t repeat yourself.
  • Methods should do just one thing.
  • Clear, intention-revealing names.
  • Comment to clarify, not explain.
  • Leave everything better than you found it.

Please check this post to learn about Salesforce Naming Conventions Best Practices.

Agreed upon software standards

Accountability

  • Commit to keeping code clean as a team
  • Hold Code reviews to enforce standards

Recording

Check the recording below to learn more with Examples.

Best practices and considerations

Please Subscribe to our YouTube channel to get notification for upcoming recording.

If you are new in Salesforce. Please check our free Salesforce Admin and Salesforce Developer training.

Apex Hours
Apex Hours

Salesforce Apex Hours is a program of the community, for the community, and led by the community. It is a space where Salesforce experts across the globe share their expertise in various arenas with an intent to help the Ohana thrive! Join us and learn about the apex hours team.

Articles: 424

3 Comments

  1. Hey Amit

    Nice video. At about the 20 minute mark in the youtube recording it looks like there is a bug in setCategory, if Amount = 50000 you don’t set the category.

    Chris

Leave a Reply

Your email address will not be published. Required fields are marked *