Primitive Data Types in Salesforce Apex

Apex uses the same primitive data types as the SOAP API. All primitive data types are passed by value, not by reference.

All Apex variables, whether they’re class member variables or method variables, are initialized to null. Make sure that you initialize your variables to appropriate values before using them. For example, initialize a Boolean variable to false.

  • Integer: A 32-bit number that does not include decimal point. Integers have a minimum value of -2, 147,483648 and maximum value of 2,147,483648.
    For example:

     Integer i = 1; 
  • Long: A 64 bit number that doesn’t includes a decimal point. Long has a minimum value of -2^63 and a maximum value of 2^63-1.
    For example:

    Long l = 2147483648L;
  • Double: A 64 bit number that doesn’t includes a decimal point. Long has a minimum value of -2^63 and a maximum value of 2^63-1.
    For example:

     Double d = 3.14159; 
  • Decimal: A number that includes a decimal point. Decimal is an arbitrary precision number. Currency fields are automatically assigned the type decimal.
    For example:

     Double d = 256.32; 
  • String: Strings are set of characters and are enclosed in single quotes. They store the text values such as name or an address.
    For example:

     String str = 'Biswajeet Samal'; 
  • Date: A value that indicates a particular day. Date values contain no information about time. Date values must always be created with system static method.
    For example:

     Date myDate = Date.newinstance(2015, 09, 14);
    Output: 2015-09-14       00:00:00
    
  • Time: A value that indicates a particular time. Time values must always be created with a system static method.
    For example:

    Time tm = newInstance(10,12,5,11);
    Output: 10:12:05
    
  • Date Time: These are data types associated with dates and times along with Date data type. The time data type stores times (hours, minutes, second and milliseconds). The Date data types stores dates (Year month and day). The time data type stores both dates and times.
    Each of these classes has a newInstance method with which we can construct particular date time values.
    For example:

    Date dt = Datetime.now();
    
  • Id: Any valid 18-character Force.com record identifier.
    For example:

    ID id='00910000004T2AGAA0';
    

    If you set ID to a 15-character value, Apex converts the value to its 18-character representation. All invalid ID values are rejected with a runtime exception.

  • Boolean: A value that can only be assigned true, false, or null.
    For example:

    Boolean isValid = true;
    
  • Blob: A value that can only be assigned true, false, or null.
    For example:

    It stores files data in binary format.
    

C# – Abstract Class vs Interface

Abstract Class:

  • An abstract class is one that is intended only to be a base class of other classes, and the “abstract” modifier is used to make a class abstract. An abstract class cannot be a sealed class. An abstract method cannot be private. The access modifier of the abstract method should be same in both the abstract class and its derived class. An abstract method cannot have the modifier virtual. Because an abstract method is implicitly virtual.
  • An abstract class can have abstract members as well non abstract members.
  • It can have constants, read only variables, instance variables and static variables.
  • We cannot create an object of abstract class.
  • Abstract class contains Constructors.
  • Only Complete Member of abstract class can be Static.
  • A class can inherit only one abstract class.
  • A class inheriting an abstract class has to override the abstract methods from abstract class while implementing them.
  • We go for Abstract classes on such situations, When we have a requirement where our base class should provide default implementation of certain methods whereas other methods should be open to being overridden by child classes use abstract classes.

Interface:

  • An interface is an entity that is defined by the word Interface, it is not a class. An interface contains only the signatures of methods. Interface members cannot have any access specifier like public, private, protected, internal or protected internal. By default all the members of an interface are Public.
  • In an interface all the members are implicitly abstract.
  • It cannot have member variables.
  • We can create an object of interface by type casting it to class name.
  • Interface doesn’t contains Constructors.
  • Member of interface can not be Static.
  • A class can implement any number of Interfaces.
  • A class implementing an interface has to implement all the methods of the interface compulsorily.
  • We go for Abstract classes on such situations, If our child classes should all implement a certain group of methods but each of the child classes is free to provide its own implementation then use interfaces.

These are the basic differences between abstract class and interface.

Salesforce Sandbox Workflow & Approval Process email alert not working

Its the effect from Spring release13 all the Sandboxes Access Email level are set default to “System Emails” only, We need to change it here -> Setup -> Email Administration -> Deliverability -> set the Access to Send Email from “System Only” to “All Emails”.

How to check if another instance of the application is running?

Sometimes we need to check the application instance running status.

var isExists = System.Diagnostics.Process.GetProcessesByName(System.IO.Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetEntryAssembly().Location)).Count() > 1;

If you want to kill the currently loading process instantly application process, you can use below code.

if (System.Diagnostics.Process.GetProcessesByName(System.IO.Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetEntryAssembly().Location)).Count() > 1) System.Diagnostics.Process.GetCurrentProcess().Kill();

You need to add a reference to System.Core.dll for the .Count() extension method. Alternatively, you can use the .Length property.