Salesforce Development Code Commenting Best Practice

by Rijwan Mohmmed
salesforce-development-code-commenting-best-practice-techdicer

Hello friends, today we will discuss Salesforce Development Code Commenting Best Practice. Creating comments in computer programs is detailing what the code is doing in a Human Readable Description. Code maintenance can be made easier and bugs can be found more quickly if comments are used correctly.

Also, check this: Lifecycle Hooks in LWC

Key Highlights :

  1. Commenting is the “ART” of describing what your program will do at a “high level”.
  2. Comments are specially marked lines of text in the program that are not evaluated.
  3. Keep track of what needs to be done.
  4. Description and clarity of what certain blocks of code do by adding context.
  5. It makes it easier for other developers when They will try to change the same code.
  6. You can install JavaDoc or ApexDoc in VS Code for Established Standards.

Process :

1. Apex Class Code Commenting: All Apex Classes header should begin with a brief comment describing the functional

/**
 * @description       : This class used for.
 * @coverage          : Test.cls | @CC100%
 * @author            : techdicerkeeplearning@gmail.com
 * @group             : Techdicer
 * @last modified on  : 05-27-2023
 * @last modified by  : techdicerkeeplearning@gmail.com
 * Modifications Log
 * Ver   Date         Author                            		Modification
 * 1.0   05-27-2023   techdicerkeeplearning@gmail.com     		Initial Version | Story Number | @CC100%
 **/

public with sharing class AccountHandler{

}

2. Apex Class Method Code Commenting: All methods should have descriptions, parameters, and return type.

/**
 * @description updates the Primary Contact field with the accoun
 * @author techdicerkeeplearning@gmail.com | 05-27-2023 | Story Number
 * @param jsonAccountList
 * @param accountIds
 * @return List<Account> returns the provided list of accounts
 **/
public static List<Account> fetchDuplicateMatchList(String jsonAccountList, Set<Id> accountIds) {
     return new List<Account>();
}

3. Apex Trigger Code Commenting: All Apex Trigger headers should begin with a brief comment describing the functional

/**
 * @description       : This Trigger used for.
 * Name               : AccountTrigger
 * @coverage          : AccountTriggerTest.cls | @CC100%
 * @author            : techdicerkeeplearning@gmail.com
 * @group             : Techdicer
 * @last modified on  : 05-27-2023
 * @last modified by  : techdicerkeeplearning@gmail.com
 * Modifications Log
 * Ver   Date         Author                            		Modification
 * 1.0   05-27-2023   techdicerkeeplearning@gmail.com     		Initial Version | Story Number | @CC100%
 **/

trigger AccountTrigger on Account (before insert, before update, after insert, after update, before delete, after delete) {

}

4. LWC HTML:

<!--
  @description       : 
  @author            : techdicerkeeplearning@gmail.com
  @group             : Techdicer
  @last modified on  : 05-27-2023
  @last modified by  : techdicerkeeplearning@gmail.com
  Modifications Log 
  Ver   Date         Author                               Modification
  1.0   05-27-2023   techdicerkeeplearning@gmail.com     		Initial Version | Story Number
-->
<template>
    <div class="slds-m-around_medium">
        <ul>
            <template for:each={data} for:item="obj">
                <li key={obj.key}>
                    <template if:true={isReportVisible}>
                        <a onclick={obj.key} href={obj.key}  target="_blank">View additional information for CIC</a>
                    </template>
                </li>
            </template>
        </ul>
    </div>
</template>

4. LWC JS:

/**
 * @description       : 
 * @author            : techdicerkeeplearning@gmail.com
 * @group             : 
 * @last modified on  : 05-27-2023
 * @last modified by  : techdicerkeeplearning@gmail.com
 * Modifications Log 
 * Ver   Date         Author                               Modification
 * 1.0   05-27-2023   techdicerkeeplearning@gmail.com     Initial Version
 * 1.1   05-27-2023   techdicerkeeplearning@gmail.com     Add Navigation in for navigate to other page
**/
import { LightningElement, wire, api, track } from "lwc";
import { NavigationMixin } from "lightning/navigation";

export default class LWC1 extends NavigationMixin(LightningElement) {

    /**
     * @description handleNavigateComponent method to naviagte the
     * @author techdicerkeeplearning@gmail.com | 05-27-2023 | Story Number 
     * @param   accountId the Account recordId 
     * @param   status  the Account record's status 
     * @summary  use navigationMixin for navigate to account record
     */
    handleNavigateComponent(accountId, status){

        if(accountId != undefined){
            this[NavigationMixin.Navigate]({
                type: 'standard__recordPage',
                attributes: {
                   recordId: accountId,
                   objectApiName: 'Account',
                   actionName: 'view'
                },
            });
        }
    }
}

Output :

Reference :

  1. Salesforce Code Commenting
  2. ApexDoc
  3. Apex prettier
What’s your Reaction?
+1
1
+1
0
+1
0
+1
0
+1
0
+1
0

You may also like

Leave a Comment