Loss of Fractions in Divisions

This is a small coding issue which can lead to serious calculation problems. When dividing numeric Integer or Long values, the fractional portion of the result, if any, is removed before performing any implicit conversions to a Double or Decimal.

Eg –

Double = 5/3; // Expected result = 1.6666666666666667 | Actual result = 1.0

To eliminate this issue, values used for division must be converted to fractions before.

Double = 5.0/3.0; // 1.6666666666666667


Double d = Double.valueOf(5)/Double.valueOf(3); // 1.6666666666666667

Quick Salesforce Deployments with ANT Migration Tool

Apache’s Ant is a Java library and command-line tool which allows quick deployment/migration of components into a target system. Once you installed Force.com migration tool, it can retrieve and deploy into target org by entering several commands. Instructions to install ANT can be found here or here. If you have installed ANT correctly, entering ant –version in the command line will display ANT version as below. If you having trouble with installation, please comment below.

Apache Ant(TM) version 1.10.0 compiled on December 27 2016

Assuming ANT is stored in c:\ANT directory, Following windows batch script allows fast & easy deployments with single line of command. Copy script into a file named deploy.bat, and execute it to do the deployment.

@RD /S /Q "C:\ANT\retrieveUnpackaged"
cd /d C:\ANT
call ant retrieveUnpackaged
call ant deployUnpackaged

Salesforce Coding Standards

This is an unofficial list of Salesforce Coding Standards sourced from various guidelines & coding standards from the internet. Salesforce recommends following Java standards for naming, that is, classes start with a capital letter, methods start with a lowercase verb, and variable names should be meaningful.

  1. Class

Class name should be noun/s starting with capital letter and follow PascalCase. Since Salesforce has different types of classes, suffixes can be used to differentiate each.

public class PageUtils { ... } // Utility Class
public class UnitSchedule { ... } // Schedule Class
public class DealBatch { ... } // Batch Class
public class AccountTest { ... } // Test Class
public class CaseWrapper { ... } // Wrapper Class
public class ErrorLogController { ... } // Controller
public class OpportunityExtension { ... } // Extension
public class LeadTriggerHandler { ... } // Trigger handler
trigger LeadTrigger  // Trigger
  1. Method Name

Method names should contain a verb and follow mixed case which begins with a lowercase letter, and the first letter of each subsequent word is capitalized. Adjectives nouns may be included in method names.

public String getWayPoint () { ... }
  1. Interfaces

Interfaces follow PascalCase similar to Classes and it should be nouns or noun phrases, or adjectives that describe behavior.  They are often prefixed with “I” to indicate as an interface.

public interface IBatchable { ... }
  1. Variables

Class and instance variables must be meaningful and mixed case (camelBack), Declare all member variables at the top of a class, with static variables at the very top.

String userName {get; set;}
Boolean isError {get; set;} // Avoid using negative booleans. eg -  Boolean isNotError
Integer ftpPort {get; set;} // Use lowercase for abbreviations
  1. Constants

In Salesforce, constants are defined with static final keyword. These constants must use all uppercase and separate words using underscore.

static final Integer PRIVATE_INT_CONST = 200;

  • Class Comments

Class comments are placed on the top of the class to provide description and copyright statement. It uses block comment of multiple lines and annotations may be included to state additional information.

* Class description goes here.
* ...
* ...
* ...
* @author  Xenon
* @version 1.0
* @since   2018-03-31
  • Method Comment

Method comments give description about related method. Similar to class comments, it uses block commenting style with annotations.

 * Method description goes here
 * @param input parameter #1
 * @param input parameter #2
 * @return return value
  • Single-line comments

Short comments can appear on a single line indented to the level of the code that follows. If a comment can’t be written in a single line, it should follow the block comment format. These comments also can be placed as a trailing comment.

// your comment here
/* your comment here */