Saturday, 27 June 2020

Salesforce Naming Conventions Best Practices

In this post we will talk about Salesforce naming conventions best practices and how to write a clean code. Salesforce naming convention is a rule to follow as you decide what to name your identifiers like class, variable, constant, method, etc. But, it is not forced to follow. So, it is known as convention not rule. Naming conventions make the application easier to read and maintain.

A well formatted code increases readability, understanding and ultimately maintainability of the code base.

Before staring with naming convention lets talk about What is PascalCase, camelCase, SNAKE_CASE ?
  1. camelCase :  Each word in the middle of the respective phrase begins with a capital letter. for example apexHours

    String firstName;
  2. PascalCase: It is same like Camel Case where first letter always is capitalized. for example ApexHours

    Class UserController{ }
  3. kebab-case: Respective phrase will be transferred to all lowercase with hyphen(-) separating words. for example apex-hours
    <c-hello-world-form></c-hello-world-form>
  4. SNAKE_CASE: Each word should be in capital with _ like . APEX_HOURS
    private static final Integer MY_INT;


Use Post Fix / Suffix:

Consistent file naming helps keep component easy to recognize and find. Here is some example of Postfix and Suffix we are using in our project from a long time.

Functional Type
Name Suffix
Examples
Trigger
Trigger
UserTrigger
Trigger Handler
TriggerHandler
UserTriggerHandler
Trigge Action
TriggerAction
UserTriggerAction
VF Controller
Controller
UserController
VF Controller Extension
Ext
UserExt
Service Class
Service
UserService
Model / Wrapper Class
Wrapper
UserWrapper
Web Service (SOAP)
Ws
UserToolsWs
Web Service (REST)
Rest
UserCreateRest
Email Service
EmlSvc
UserCreateEmlSvc
Asynchronous (Future)
Async
UserCreateAsync
Asynchronous (Batch)
Batch
UserCreateBatch
Scheduled Apex
Job
UserCleanupJob
Test Class
Test
UserCreateTest
Queueable Apex
Que
UserSyncingQue
Visualforce Page
-none-
UserClone
Visualforce Component
Cmp
UserCloneCmp
Lightning Components






APEX NAMING CONVENTION :

  1. Class Name :  Class names should be unique, beginning with an uppercase letter. It should NOT contain underscores or spaces (except from the prefix and suffix).  Class names should be nouns in mixed cases, with first letter of each interval word capitalized. For Example

    ClassNamePOSTFIX
  2. Variable Name : Variables should be in mixed case with a lowercase first letter. Internal words start with capital letters. Variable names should be short and sweet and meaningful. Its should be camelCase like accountList

    List<Account> accountList;
  3. Method Name : Methods should be verbs, in mixed case with the first letter lowercase, with the first letter of each internal word capitalized. Whole words should be  used and use of acronyms and abbreviations should be limited. Name should be camelCase like  

    showAccountDetail();
  4. Constants : The names of variables declared class constants should be all uppercase with words separated by underscores (“_”). All uppercase letters in this format : CONSTANT_NAME Example: 

    private static final String ACCOUNT_LIMIT ='10';
  5. Trigger : <ObjectName>Trigger. This should follow Salesforce Trigger Patterns - One trigger per object

    UserTrigger


Visualforce Pages

This should PascalCase, No underscores or spaces and use whole words, limit acronym or abbreviation like below.
AccountClone


Lightning Web Components Naming Convention


Please check this post to leanr about LWC naming Convention.

  1. Html File :  Use camel case to name your component and use kebab-case to reference a component in the markup. For Example

    helloWorld.html
  2. JavaScript File : Java Script Class name should be in PascalCase like below example

    export default class HelloWorld extends LightningElement{
    }
  3. CSS File : Methods should be verbs, in mixed case with the first letter lowercase, with the first letter of each internal word capitalized. Whole words should be  used and use of acronyms and abbreviations should be limited. Name should be camelCase like  

    showAccountDetail();

 

CSS Class Naming Standards

  • CSS classes should be named based on the component that is being addressed
  • Any name that is longer than one word, needs to be in this format : class-name
  • Multi word name should be separated by a " - "


Lightning Component

Lightning component names must be unique. They should begin with a lowercase letter. All components should end with the suffix “Cmp”. like  

userCardCmp (Initial lower case letter and suffixed with “Cmp” ) 

Lightning Events

Lightning event names must be unique. They should begin with a lowercase letter. All events should end with the suffix “Evt” . like   

userEvt (Initial lowercase letter and suffixed with “Evt” )

 

Check below recording to learn about how to write clean code in Salesforce.




Further learning

Tuesday, 16 June 2020

Navigation Service in Lightning Web Components | Mixin


The Lightning navigation service allows you to navigate in Lightning Experience, Lightning Communities and the Salesforce app. To generate a URL or navigate to a page reference, use the lightning-navigation service wire adapters and functions.

PageReference is a JavaScript object that describes the page type, its attributes, and the state of the page.

Step 1) Import lightning/navigation
import { NavigationMixin } from 'lightning/navigation';

Step 2) Apply the NavigationMixin function to your component’s base class.

export default class MyCustomElement extends NavigationMixin(LightningElement) {
}

Step 3) Call the navigation service’s [NavigationMixin.Navigate] function to dispatch the navigation request and open the New Course Delivery modal dialog.

onAddNewDelivery() {
     this[NavigationMixin.Navigate]({
         type: 'standard__objectPage',
         attributes: {
             objectApiName: 'Student__c',
             actionName: 'new'
         }
     });
 }

What is a Mixin?

A mixin lets us add functionality to a class without extending it. Useful when a class already extends a parent class, because a class can only extend a single parent.


Check this recording after 1st hours.





Monday, 1 June 2020

Google chrome extensions for Salesforce

There are lots of other awesome Salesforce Google chrome extensions are available in market. But in this post we will talk about above 9 top google chrome extension for Salesforce.
  1. Salesforce Organizer : The ORGanizer Chrome Extension (BETA) lets you forget about your Salesforce.com username and passwords and help you to recognize Salesforce.com tabs on your browser. Its also have lots of other feature. Please check our recording for that.
  2. Advanced Code Searcher : Enables you to quickly search through your instances Apex classes, triggers, Visualforce pages and components. Its also provide Code Coverage Extract, ApexPMD report and This extension now allows you to lint the lightning code via the Lightning Linter tab.
  3. Force.com Login: Helps you manage Salesforce login credentials and lets you login with 1 click.
  4. Salesforce API Name: Small extension to toggle between API field names and labels on salesforce detail pages
  5. Salesforce Coloured favicons: Overrides the standard salesforce favicon with one colored based on the org. Also, displays a separate icon for sandbox instances
  6. Salesforce DevTools : Powerful Salesforce developer tools, includes Query Editor, Fields definition, ERDs, Page Layout, and others
  7. Apex Debugger : Debug Salesforce apex code with ease, Improved debug logs for Salesforce
  8. Salesforce Navigator : This extension helps you get to any salesforce page quickly. Just type in what you need to do
  9. Salesforce Inspector : An extension to add a metadata layout on top of the standard Salesforce UI to improve the productivity and joy of Salesforce configuration, development, and integration work.


Which Google chrome extensions you like?

Thanks