Order of execution in Visualforce page

1. Constructor of the controller.

2. Action method of the page.

3. Getter methods.

Sample Code:

Visualforce page:

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

Apex Controller:

public with sharing class Sample {

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

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

Output:


Cheers!!!

How to show profile photo in Visuaforce page?

Sample Code:

Visualforce page:

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

Apex Controller:

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

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


}

Output:



Cheers!!!

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 =: 
                                        UserInfo.getUserId()];
        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 =: 
                                        UserInfo.getUserId()];
        if(listEntitySub.size() > 0) {
            delete listEntitySub;
            return 'Unsubscribed';
        } else {
            return 'You are not subscribed to this';
        }
    }
}

Subscribe button code:

{!REQUIRESCRIPT("/soap/ajax/15.0/connection.js")}; 
{!REQUIRESCRIPT("/soap/ajax/15.0/apex.js")}; 
alert(sforce.apex.execute("InfallibleTech.SubscribeOrUnsubscribeLead","subscribeLead",{leadId:"{!Lead.Id}"})); 
location.reload(true);


Unsubscribe button code:

{!REQUIRESCRIPT("/soap/ajax/15.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/15.0/apex.js")} 

alert(sforce.apex.execute("InfallibleTech.SubscribeOrUnsubscribeLead","unSubscribeLead",{leadId:"{!Lead.Id}"})); 
location.reload(true);


Output:


Cheers!!!

Unexpected Token Illegal

If you face this issue, modify the code as below

alert(sforce.apex.execute("InfallibleTech.SubscribeOrUnsubscribeLead","unSubscribeLead",{"{!Lead.Id}"}));

For String and Id, quotes should be used.

Cheers!!!

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:

{!REQUIRESCRIPT("/soap/ajax/15.0/connection.js")};
{!REQUIRESCRIPT("/soap/ajax/15.0/apex.js")};
alert(sforce.apex.execute("InfallibleTech.SubscribeOrUnsubscribeLead","subscribeLead",{leadId:"{!Lead.Id}"}));
location.reload(true);

Cheers!!!

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.

Cheers!!!

getGlobalDescribe() in Apex in Salesforce

getGlobalDescribe():

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

Cheers!!!

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]));

Note:
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.

Cheers!!!

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

Cheers!!!

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.

Note:
For more information, check the below link

http://developer.force.com/codeshare

Cheers!!!

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.

Cheers!!!

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.

Cheers!!!
Log Category
Description
Database
Includes information about database activity, including every data manipulation language (DML) statement or inline SOQL or SOSL query.
Workflow
Includes information for workflow rules, flows, and processes, such as the rule name, the actions taken, and so on.
Validation
Includes information about validation rules, such as the name of the rule, whether the rule evaluated true or false, and so on.
Callout
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.
Visualforce
Includes information about Visualforce events, including serialization and deserialization of the view state or the evaluation of a formula field in a Visualforce page.
System
Includes information about calls to all system methods such as the System.debugmethod.

Cheers!!!

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.

Cheers!!!

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.

Cheers!!!

Users tab alternative in Salesforce

Users tab alternative in Salesforce is People Tab.




Note:

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.

Cheers!!!

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.



Output:


Cheers!!!

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

https://chrome.google.com/webstore/detail/salesforce-advanced-code/lnkgcmpjkkkeffambkllliefdpjdklmi?utm_source=chrome-ntp-icon

2. Click "ADD TO CHROME".


3. Click "Add" to confirm.


4. Go to your Salesforce organization and experience it.


Cheers!!!

Salesforce Lightning Component Study Guide

http://www.infallibletechie.com/2016/05/salesforce-lightning-tutorial.html

The best source for Salesforce Lightning Component Study Guide is

https://www.salesforce.com/services-training/learnlightning.jsp

Note:

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.

Cheers!!!

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>
</apex:form>
</apex:page>

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

Output:


Cheers!!!

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>
    <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:form>
    </apex:toolbarGroup>
</apex:toolbar>
</apex:page>

Output:


Cheers!!!

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>
    </apex:panelBar>
</apex:page>

Output:



Cheers!!!

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
</apex:page>

Adding Visualforce page to the page layout:


Output:


Cheers!!!

How to setup Duplicate Management in Salesforce?

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

http://www.infallibletechie.com/2015/05/duplicate-management-in-salesforce.html

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.


Output:



Cheers!!!

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

http://www.infallibletechie.com/2015/05/how-to-setup-duplicate-management-in.html

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.

Cheers!!!

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.

Note:

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

Cheers!!!

Fastest way to answer your Salesforce queries

1. Login into your Twitter account.

2. Tweet to AskSalesforce.

Sample Tweet:


Cheers!!!

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.


Output:


Cheers!!!

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.


Cheers!!!

How to enable Lightning Components in Salesforce

1. Give Namespace to your Salesforce organization.

For giving Namespace, follow the below link

http://www.infallibletechie.com/2015/05/whats-namespace-in-salesforce.html

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


3. Enable Lightning Components.


Cheers!!!