Category Archives: Salesforce

How to include one visualforce page within another?

<apex:page sidebar="false" id="TestPage">
    <p>Inner Visualforce Page Before</p>
        <apex:include pagename="TestChart"></apex:include>
    <p>Inner Visualforce Page After</p>

Note: Here in above sample visualforce page “TestPage” is the main page and “TestChart” is another visulaforce page within “Testpage”.

Salesforce: Add Approve/Reject Link in Email template for approval

Sometimes we need to customize the email that goes out to an approver with the record approve link, Where can approver find the link to approve or reject the record.

We can use the Merge field {!ApprovalRequest.External_URL} or {!ApprovalRequest.Internal_URL} to add approve link in email template.

Follow below steps:

  • In the Available Merge Fields select Field Type as Approval Fields.
  • Select Field as Internal Approval URL or External Approval URL.
  • Copy and paste the merge field value into your template.

Note: Approval process merge fields can be used in email templates, but not mail merge templates. Because email notifications to a queue aren’t intended for an external audience, any instances of the merge field {!ApprovalRequest.External_URL} in the email template are sent as the equivalent internal URL.

Use of immediate attribute of commandbutton & commandlink in visualforce page.

Basically we used immediate="true" in CommandButton & CommandLink, when we don’t want our validation rules to be fired during any server request.

It is a Boolean value that specifies whether the action associated with this component should happen immediately, without processing any validation rules associated with the fields on the page. If set to true, the action happens immediately and validation rules are skipped. If not specified, this value defaults to false.

We generally use it to make functionality of “Cancel” button or “Back” button, where we don’t want validation rule to get executed. If we don’t use immediate=true then on click of cancel button also, validation rules will get executed.

Here is the sample code:

<apex:commandlink action="{!cancel}" value="Cancel" styleclass="btn" id="btnCancel" immediate="true">

SOQL Query to Select All Fields of sObject

Sample Code:

public class DynamicSOQL {
  public static sObject getAllFieldsData(String objTypeName) {
        sObject sObj;
        Schema.DescribeSObjectResult[] descSObj = Schema.describeSObjects(new String[]{objTypeName});
        Map<String, Schema.SObjectField> fieldMap = descSObj[0].fields.getMap();
        List<String> fieldNames = new List<String>(fieldMap.keySet());
        system.debug('Fields-' + String.join(fieldNames, ','));
        String queryString = 'SELECT '+ String.join(fieldNames, ',') +' FROM '+ objTypeName +' LIMIT 1';
        sObj = Database.query(queryString);
        return sObj;

Highlight Selected Row in a table in Visualforce Page

Here is an example to highlight the selected row in a page block table in visualforce page. To do this add the below code snippet to your visualforce page to highlight the selected row color among the rest of the rows in same page block table.

Visualforce Page:

<apex:page standardController="Account" recordSetVar="Accounts" sidebar="false" showHeader="false">  
    <apex:includeScript value=""/>  
        border: 1px solid #fbd850;
        background: rgb(199,199,199);
        font-weight: bold;
        color: #eb8f00;
    function highlightRow(row){  
    <apex:form >  
        <apex:pageBlock >  
            <apex:pageBlockTable value="{!accounts}" var="a">  
                <apex:column value="{!a.Name}" onclick="highlightRow(this)"/>  
                <apex:column value="{!a.AccountNumber}" onclick="highlightRow(this)"/>
                <apex:column value="{!a.Type}" onclick="highlightRow(this)"/>  
                <apex:column value="{!a.Industry}" onclick="highlightRow(this)"/>  
                <apex:column value="{!a.Phone}" onclick="highlightRow(this)"/>  


Note: If you want to change the Highlighted color, you can write your won style class.