Tag Archives: SFDC

Salesforce StandardController Methods

The following methods are for StandardController:

addFields(fieldNames)
When a Visualforce page is loaded, the fields accessible to the page are based on the fields referenced in the Visualforce markup. This method adds a reference to each field specified in fieldNames so that the controller can explicitly access those fields as well.

cancel()
Returns the PageReference of the cancel page.

delete()
Deletes record and returns the PageReference of the delete page.

edit()
Returns the PageReference of the standard edit page.

getId()
Returns the ID of the record that is currently in context, based on the value of the id query string parameter in the Visualforce page URL.

getRecord()
Returns the record that is currently in context, based on the value of the id query string parameter in the Visualforce page URL.

reset()
Forces the controller to reacquire access to newly referenced fields. Any changes made to the record prior to this method call are discarded.

save()
Saves changes and returns the updated PageReference.

view()
Returns the PageReference object of the standard detail page.

Salesforce StandardSetController Methods

The following methods are for StandardSetController:

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

first()
Returns the first page of records.

getCompleteResult()
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.

getFilterId()
Returns the ID of the filter that is currently in context.

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

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

getListViewOptions()
Returns a list of the listviews available to the current user.

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

getPageSize()
Returns the number of records included in each page set.

getRecord()
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.

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

getResultSize()
Returns the number of records in the set.

getSelected()
Returns the list of sObjects that have been selected.

last()
Returns the last page of records.

next()
Returns the next page of records.

previous()
Returns the previous page of records.

save()
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.

setFilterID(filterId)
Sets the filter ID of the controller.

setpageNumber(pageNumber)
Sets the page number.

setPageSize(pageSize)
Sets the number of records in each page set.

setSelected(selectedRecords)
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:
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")}

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;
}

Example:

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:
    CASESAFEID(Id)
  • Set Field Visibility, add/ remove from Page Layout(s).
  • Click Save.

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