Order of execution in Visualforce page

1. Constructor of the controller.

2. Action method of the page.

3. Getter methods.

4. If there are any client-side technologies on the page, such as JavaScript, the browser executes them. Example is window.onLoad().

If the page contains an <apex:form> component, all of the information necessary to maintain the state of the database between page requests is saved as an encrypted view state. The view state is updated whenever the page is updated.

Sample Code:

Visualforce page:

<apex:page controller="Sample" action="{!sav}">
    <apex:outputText >{!mem}</apex:outputText>

Apex Controller:

public with sharing class Sample {

    public String mem {
       get { return 'getter';}  

    public sample() {
        mem = 'constructor';
    public void sav() {
        mem = 'action';



How to show profile photo in Visuaforce page?

Sample Code:

Visualforce page:

<apex:page controller="Sample">
    <apex:pageBlock >
        <apex:image value="{!photoURL}"/>

Apex Controller:

public class Sample {
    public String photoURL {get;set;}

    public sample() {
        photoURL = [SELECT Id, smallPhotoURL FROM User WHERE ID =: UserInfo.getUserId()].smallPhotoURL;




Follow and Unfollow records using apex in Salesforce

Sample Code:

global class SubscribeOrUnsubscribeLead {
    webservice static String subscribeLead(Id leadId) {
        List<EntitySubscription> listEntitySub = new List<EntitySubscription>();
        listEntitySub = [SELECT Id FROM EntitySubscription WHERE ParentId =: leadId AND SubscriberId =: 
        if(listEntitySub.size() == 0) {
            EntitySubscription entitySub = new EntitySubscription(ParentId = leadId, SubscriberId = UserInfo.getUserId());
            insert entitySub;
            return 'Subscribed';
        } else {
            return 'You have already subscribed';
    webservice static String unSubscribeLead(Id leadId) {
        List<EntitySubscription> listEntitySub = new List<EntitySubscription>();
        listEntitySub = [SELECT Id FROM EntitySubscription WHERE ParentId =: leadId AND SubscriberId =: 
        if(listEntitySub.size() > 0) {
            delete listEntitySub;
            return 'Unsubscribed';
        } else {
            return 'You are not subscribed to this';

Subscribe button code:


Unsubscribe button code:





Unexpected Token Illegal

If you face this issue, modify the code as below


For String and Id, quotes should be used.


Problem with Onclick JavaScript 'No operation available for request...'

If you face "Problem with Onclick JavaScript 'No operation available for request...'" issue, check the below

If you have Namespace prefix, you have to write the code as below in the button.

Sample Code:



How to create custom object tab in Salesforce?

1. Go to setup --> Create --> Tabs.

2. Click "New" in Custom Object Tabs section.

To create records, go to the tab and click "New" button.


getGlobalDescribe() in Apex in Salesforce


Returns a map of all sObject names (keys) to sObject tokens (values) for the standard and custom objects defined in your organization.

Sample map:

public static Map<String, Schema.SObjectType> getGlobalDescribe()


StandardSetController Instantiation

You can instantiate a StandardSetController in either of the following ways:

1. From a list of sObjects:
List<account> accountList = [SELECT Name FROM Account LIMIT 20];
ApexPages.StandardSetController ssc = new ApexPages.StandardSetController(accountList);

2. From a query locator:
ApexPages.StandardSetController ssc =
new ApexPages.StandardSetController(Database.getQueryLocator([SELECT Name,CloseDate FROM Opportunity]));

The maximum record limit for StandardSetController is 10,000 records. Instantiating StandardSetController using a query locator returning more than 10,000 records causes a LimitException to be thrown. However, instantiating StandardSetController with a list of more than 10,000 records doesn’t throw an exception, and instead truncates the records to the limit.


Using the instanceof Keyword in Apex in Salesforce

If you need to verify at run time whether an object is actually an instance of a particular class, use the instanceof keyword. The instanceof keyword can only be used to verify if the target type in the expression on the right of the keyword is a viable alternative for the declared type of the expression on the left.

You could add the following check to the Report class in the classes and casting example before you cast the item back into a CustomReport object.

If (Reports.get(0) instanceof CustomReport) {
    // Can safely cast it back to a custom report object
   CustomReport c = (CustomReport) Reports.get(0);
   } Else {
   // Do something with the non-custom-report.


Force.com Code Share

Code Share is a directory of open source code projects covering all aspects of the Force.com Platform. Browse and access the source code for these projects to learn more about the code. Create an account of your own on Code Share to collaborate with project owners and other members on existing projects, and create and register projects of your own.

For more information, check the below link



CreatedDate field in Salesforce

CreatedDate field in Salesforce is

1. DateTime field.

2. In before insert trigger, the value will be null.

3. Generated only after successful insertion.

4. Provides the exact date and time of the record creation.


Test class for Email Services classes in Salesforce

In the test class, follow the below

1. Create Messaging.InboundEmail.

2. Create Messaging.InboundEnvelope.

3. Pass them to handleInboundEmail() method of Messaging.InboundEmailHandler class.

Sample Test Class Code:

Messaging.InboundEmail email = new Messaging.InboundEmail() ;
Messaging.InboundEnvelope env = new Messaging.InboundEnvelope();

email.subject = 'Test';
email.fromname = 'Test Test';
env.fromAddress = 'Test@email.com';
email.plainTextBody = 'Test';

CreateLeadInboundHandler emailProcess = new CreateLeadInboundHandler();
emailProcess.handleInboundEmail(email, env);

here CreateLeadInboundHandler is a Email Service controller class.

Log Category
Includes information about database activity, including every data manipulation language (DML) statement or inline SOQL or SOSL query.
Includes information for workflow rules, flows, and processes, such as the rule name, the actions taken, and so on.
Includes information about validation rules, such as the name of the rule, whether the rule evaluated true or false, and so on.
Includes the request-response XML that the server is sending and receiving from an external Web service. This is useful when debugging issues related to using Force.comWeb services API calls.
Apex Code
Includes information about Apex code and can include information such as log messages generated by DML statements, inline SOQL or SOSL queries, the start and completion of any triggers, and the start and completion of any test method, and so on.
Apex Profiling
Includes cumulative profiling information, such as the limits for your namespace, the number of emails sent, and so on.
Includes information about Visualforce events, including serialization and deserialization of the view state or the evaluation of a formula field in a Visualforce page.
Includes information about calls to all system methods such as the System.debugmethod.


When to use Apex in Salesforce?

Use Apex if you want to:

1. Create Web services.
2. Create email services.
3. Perform complex validation over multiple objects.
4. Create complex business processes that are not supported by workflow.
5. Create custom transactional logic (logic that occurs over the entire transaction, not just with a single record or object).
6. Attach custom logic to another operation, such as saving a record, so that it occurs whenever the operation is executed, regardless of whether it originates in the user interface, a Visualforce page, or from SOAP API.

For more information, see the Force.com Apex Code Developer's Guide.


When to use Visualforce in Salesforce?

Visualforce is a framework that allows developers to build sophisticated, custom user interfaces that can be hosted natively on the Force.com platform. The Visualforce framework includes a tag-based markup language, similar to HTML, and a set of server-side “standard controllers” that make basic database operations, such as queries and saves, very simple to perform.

Visualforce consists of a tag-based markup language that gives developers a more powerful way of building applications and customizing the Salesforce user interface. With Visualforce you can:

1. Build wizards and other multi step processes.

2. Create your own custom flow control through an application.

3. Define navigation patterns and data-specific rules for optimal, efficient application interaction.


Users tab alternative in Salesforce

Users tab alternative in Salesforce is People Tab.


People tab shows only the active users in the organization. For Inactive users, go to Setup --> Manage Users --> Users where you can find both Active and Inactive users in the organization.


Simple Search in LinkedIn using apex in Salesforce

1. Create a button "Search in LinkedIn" in Contact object.

2. Add the button to the page layout.

3. Click the button to see the result.



Salesforce advanced Code searcher - Google Chrome Extension

By using the advanced quick find you can get your code few clicks shorter. Also, you can search any string your code
Using this extension you can search your code components your salesforce instance:
1) apex Classes
2) Apex Triggers
3) visualforce Pages
4) Visualforce Components

In addition to the above you can use this extension to jump to classes / pages / triggers from the advanced quick find section on the left hand side.

1. Go to this link


2. Click "ADD TO CHROME".

3. Click "Add" to confirm.

4. Go to your Salesforce organization and experience it.


Salesforce Lightning Component Study Guide


The best source for Salesforce Lightning Component Study Guide is



For examples and practical exposure to Salesforce Lightning Component, kindly search in this site using search option. I have posted many examples in this site.


apex:vote Example

Go to Ideas tab and create an idea.

Sample Visualforce page:

<apex:page id="thePage">
<apex:form >
    <apex:vote objectId="087U00000004ZU7"></apex:vote>

here "087U00000004ZU7" is id of an idea created.



Toolbar using apex in Salesforce

Sample Code:

<apex:page id="thePage">
<apex:toolbar id="theToolbar">
    <apex:outputText value="Sample Toolbar"/>
    <apex:toolbarGroup itemSeparator="line" id="toobarGroupLinks">
        <apex:outputLink value="http://www.infallibletechie.com">Infallible Techie</apex:outputLink>
        <apex:outputLink value="http://www.salesforce.com">Salesforce</apex:outputLink>
    <apex:toolbarGroup itemSeparator="line" location="right" id="toobarGroupForm">
        <apex:form id="theForm">
            <apex:inputText id="theInputText">Enter Text: </apex:inputText>
            <apex:commandLink value="search" id="theCommandLink"/>



apex:panelBar example

Sample Code:

<apex:page >
    <apex:panelBar >
        <apex:panelBarItem label="Item 1">Panel Bar Example 1</apex:panelBarItem>
        <apex:panelBarItem label="Item 2">Panel Bar Example 2</apex:panelBarItem>
        <apex:panelBarItem label="Item 3">Panel Bar Example 3</apex:panelBarItem>



What are the inline Visualforce pages in Salesforce?

A Visualforce page with attribute standardController with an object name can be referenced inside the page layouts of the object. This is nothing but Inline Visualforce page.

Sample Visuaforce page:

<apex:page standardController="Account">
This is Inline Visualforce page

Adding Visualforce page to the page layout:



How to setup Duplicate Management in Salesforce?

To know about Duplicate management in Salesforce, use the below link


Follow the below steps for setting up Duplicate Management in Salesforce

1. Go to Setup --> Administer --> Data.com Administration --> Duplicate Management --> Matching Rules.

2. Click "New Rule".

3. Select an object for Matching Rule.

4. Save the matching rule.

5. Activate the matching rule.

6. Go to Setup --> Administer --> Data.com Administration --> Duplicate Management --> Duplicate Rules.

7. Select the object in New Rule menu.

8. Save the duplicate Rule.

9. Activate the Duplicate Rule.


Duplicate Management in Salesforce

Maintaining clean and accurate data is one of the most important things you can do to help your organization get the most out of Salesforce. Use Data.com Duplicate Management to control whether and when you allow users to create duplicate records inside Salesforce; customize the logic that’s used to identify duplicates; and create reports on the duplicates you do allow users to save.

Check the below link for setting up Duplicate Management in Salesforce


Duplicate Management Limitations

1. Duplicate management is available for accounts, contacts, leads, and custom objects. All other objects, including Opportunities and Person Accounts, are not currently supported.
2. Duplicate rules don’t run when records are created in following ways.
    i)   When records are created using Quick Create.
    ii)  When leads are converted to accounts or contacts and your organization doesn’t have the “Use  Apex Lead Convert” permission.
    iii) When a record is restored with the Undelete button.
    iv) When records are added using Exchange Sync.
    v)  When records are manually merged.

Adoption Manager in Salesforce

Salesforce Adoption Manager guides users with customized suggestions based on how they use Salesforce and the Salesforce1 mobile app. Help your users succeed with tips on actions they can take to accomplish more—faster.

Once you activate the program, it will start with a personalized invite to users to download the Salesforce1 mobile app. All emails are optimized for desktop and mobile devices. Users not on mobile devices will have the option to text a download link to themselves.


As of now, it is available only for U.S based organization only.


Fastest way to answer your Salesforce queries

1. Login into your Twitter account.

2. Tweet to AskSalesforce.

Sample Tweet:


Simple Salesforce Lightning app development

1. Go to Developer Console.

2. Go to File --> New --> Lightning Component.

3. Enter Name and Description and click "Submit" button.

4. Enter some Text between <aura:component> and </aura:component> tags.

5. Save the component by navigating to File --> Save.

6. Go to File --> New --> Lightning Application.

7. Enter Name and Description and click "Submit" button.

8. Embed the component by entering Namespace:componentName between <aura:application> and </aura:application> tags.

9. Click "Preview" button to preview the application.



How to hide the default account team option from user details section in Salesforce?

1. Go to Setup --> Accounts --> Account Teams.

2. Click "Disable Account Teams".

3. Deselect the Account Teams Enabled check box and click "Save" button.


How to enable Lightning Components in Salesforce

1. Give Namespace to your Salesforce organization.

For giving Namespace, follow the below link


2. Go to Setup --> Develop --> Lightning Components.

3. Enable Lightning Components.