Tag Archives: Salesforce.com

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.
    

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”.

SOQL query to get last 90days created records

There is a feature of SOQL called ‘Date Literals’, Using this we can simply write query to get last 90days created records.
The below query will fetch accounts where it’s Created Dtae is more than 90 Days.

Sample SOQL:

 SELECT Id FROM Account WHERE CreatedDate > LAST_90_DAYS

There are a lot of other ‘Date Literals’ that we can use. Here is the full reference.

Hard Delete record using Apex in Salesforce

We can hard delete record or list of records using emptyRecycleBin() function in apex. Pass the record or record list to emptyRecycleBin() to delete it from Recycle Bin.

Contact con = new Contact(Id = '09k110000O5abc');
Database.emptyRecycleBin(con);

Note: The DML operation datatbase.emptyRecycleBin() is limited to 200 items.