Notifications
Clear all
Oct 06, 2021 5:26 pm
Naming conventions and program commenting to follow while doing Salesforce Apex code development?
1 Reply
Oct 06, 2021 5:27 pm
Naming conventions and best practices. Check these out:
See this Apex code/program/class commenting sample below:
/* @Name ScheduleDynamic * @Author First Name <author@email.com> * @Date 10 Jan, 2022 * @Description - Give a detailed description of what your program * does, so you and others can easily understant what id does later on. *------------------------------------------------------------------------------------------- * Modification Log: * Version Developer Date Description *------------------------------------------------------------------------------------------- * 1.0 Firstname 10 Jan, 2022 Initial Creation *-------------------------------------------------------------------------------------------*/
Method level commenting:
/* @Description This method gets checks for entries in org cache and returns it * @Param String - Key string * @Return Object - Value retrieved from org cache. * @Example CacheService.getFromOrgCache('accessToken') *-------------------------------------------------------------------------------------------*/ public static Object getFromOrgCache(String cacheKey) { if (Cache.Org.contains(cacheKey)) { return Cache.Org.get(cacheKey); }else { return null; } }
Also check this out to generate code documentation from code comments:
Following is what I use in my VS Code custom Snippets (in apex.json - file depending on language).
To create or edit your own snippets, select User Snippets under File > Preferences. Details can be found at https://code.visualstudio.com/docs/editor/userdefinedsnippets
"Program / Class Comment": { "prefix": "comment-program-class", "body": [ "/* @Name $TM_FILENAME", " * @Author Colbridge <colbridge@colbridge.com>", " * @Date $CURRENT_DATE $CURRENT_MONTH_NAME_SHORT, $CURRENT_YEAR", " * @Description - $1Describe what the program/class does here.", " *-------------------------------------Update History----------------------------------------", " * Version Developer Date Description", " *-------------------------------------------------------------------------------------------", " * 1.0 Colbridge 19 Jan, 2022 Describe what modifications you made here.", " *-----------------------------------------------------------------------------------------*/" ], "description": "Program/class comment to place on top of Apex class/file." }
Following snippet is for method commenting:
"Method Comment": { "prefix": "comment-method", "body": [ "/* @Description - This method gets checks for entries in org cache and returns it", " * @Param String - Key string", " * @Return Object - Value retrieved from org cache.", " * @Example CacheService.getFromOrgCache('accessToken')", " *-----------------------------------------------------------------------------------------*/" ], "description": "Method comment to place on top of Apex methods." }
Hope this helps!