Author Archives: Biswajeet

About Biswajeet

Biswajeet is my Name, Success is my Aim and Challenge is my Game. Risk & Riding is my Passion and Hard Work is my Occupation. Love is my Friend, Perfection is my Habit and Smartness is my Style. Smiling is my Hobby, Politeness is my Policy and Confidence is my Power.

Salesforce StandardSetController Methods

The following methods are for StandardSetController:

Returns the PageReference of the original page, if known, or the home page.

Returns the first page of records.

Indicates whether there are more records in the set than the maximum record limit. If this is false, there are more records than you can process using the list controller. The maximum record limit is 10,000 records.

Returns the ID of the filter that is currently in context.

Indicates whether there are more records after the current page set.

Indicates whether there are more records before the current page set.

Returns a list of the listviews available to the current user.

Returns the page number of the current page set. Note that the first page returns 1.

Returns the number of records included in each page set.

Returns the sObject that represents the changes to the selected records. This retrieves the prototype object contained within the class, and is used for performing mass updates.

Returns the list of sObjects in the current page set. This list is immutable, i.e. you can’t call clear() on it.

Returns the number of records in the set.

Returns the list of sObjects that have been selected.

Returns the last page of records.

Returns the next page of records.

Returns the previous page of records.

Inserts new records or updates existing records that have been changed. After this operation is finished, it returns a PageReference to the original page, if known, or the home page.

Sets the filter ID of the controller.

Sets the page number.

Sets the number of records in each page set.

Set the selected records.

Custom Send Email Button on Custom Objects

  • Go to Setup | Create | Objects.
  • Select your Custom Object.
  • Go to the Custom Buttons, Links and Actions section.
  • Click on New Button or Link.
  • Create a New Custom Button.
  • Select the Display Type as Detail Page Button.
  • Select the Behavior as Execute JavaScript.
  • Select the Content Source as OnClick JavaScript.
  • Include below code:

window.location = '/_ui/core/email/author/EmailAuthor?rtype=003&p3_lkid={!CustomObject__c.Id}&retURL=/{!CustomObject__c.Id}&p5={!$User.Email}&p24="{!CustomObject__c.To_Email__c}&template_id=00X90000001FCj4';

Note: If the custom object holds some of the contact details then you would need to use the values from custom object, not the contact object.

Save it. Edit the Page Layout of the Custom Object and drag this button on to the Page Layout under the Custom Button section.

The information shown below are the parameters that can be added in the URL. Fields that are mark with asterisk are always needed in the URL.

Parameter Name Parameter Value
p2_lkid To (can be Contact or Lead Id)
p3_lkid Related To (usually the parent record Id)
p4 CC
p5 BCC
p6 Subject
p23 Email Body
p24 Additional To
Template_Id Salesforce email template Id
retURL Redirection page when cancel button is clicked

Function to Calculate the 18 Character ID From 15 Character ID

public String Convert15CharTo18CharId(String id) {
    String suffix = '';
    Integer flags;

    for (integer i = 0; i < 3; i++) {
        flags = 0;
        for (Integer j = 0; j < 5; j++) {
            String c = id.substring(i * 5 + j, i * 5 + j + 1);
            //Only add to flags if c is an uppercase letter:
            if (c.toUpperCase().equals(c) && c >= 'A' && c <= 'Z') {
                flags = flags + (1 << j);
        if (flags <= 25) {
            suffix = suffix + 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'.substring(flags, flags + 1);
        } else {
            suffix += '012345'.substring(flags - 26, flags - 25);
    String convertId = id + suffix;
    //18 Digit Id with checksum
    System.debug('convertId-' + convertId);
    return 18 digitId;


String Id = '0019000001EJNfj';
String convertedId = Convert15CharTo18CharId(Id);

Formula Field to Convert 15 Character ID to 18 Character ID

Follow the below steps to create a formula field that will give you the 18 characters ID of the records.

  • Go to Setup | Customize | object name | click Fields
    (For Custom objects: Setup | Create | Objects | Object Name)
  • In the related list “Custom Fields & Relationships” click New.
  • Click the Formula radio button.
  • Click the Text radio button for “Formula Return Type”.
  • 6. Input the following Formula into the Formula Editor:
  • Set Field Visibility, add/ remove from Page Layout(s).
  • Click Save.

NOTE: When dealing with record types only custom record types have ids.

PHP Function to Calculate the Salesforce 15 Character ID to 18 Charachter ID

function salesForceIdCalculate($id)
    $map      = implode('', array_merge(range('A', 'Z'), range(0, 9)));
    $checksum = '';
    foreach (str_split($id, 5) as $chunk) {
        $checksum .= substr($map, bindec(strrev(array_reduce(str_split($chunk, 1), function($carry, $item)
            $carry .= (!is_numeric($item) && $item == strtoupper($item)) ? '1' : '0';
            return $carry;
        }, ''))), 1);
    return $checksum;

// example
//$_15ID = '0019000001EJNfj';
//$_18ID = $_15ID. salesForceIdCalculate($_15ID);