Concepts or coding lessons of Salesforce that you can implement easily

WhatsApp on Salesforce Integration in 5 Steps

WhatsApp's Click to Chat feature allows you to begin a chat with someone without having their phone number saved in your phone's address book. 
As long as you know this person’s phone number, you can create a link that will allow you to start a chat with them. 
By clicking the button, a chat with the person automatically opens. 
Click to WhatsApp Chat works on both your phone and WhatsApp Web.

1. Go to Setup -> Contacts -> Button and links
2. Click on New Button and Links button
3. Enter below required details:
Label: Click to WhatsApp Chat
Name: Click_to_WhatsApp_Chat
Display Type: Detail Page Button
Behavior: Display in New Window
Content Source: URL 



4. Use below URL in the text area:

https://api.whatsapp.com/send?phone={!Contact.Phone}&text={!JSENCODE("Hi "& Contact.Name &", Hope you are doing good. I want to connect with you regarding our new product.")}

5. Add this new button to the contacts page layout.

Now go to any contact which has correct phone number populated and click on Click to WhatsApp Chat button.

Note:
Use https://api.whatsapp.com/send?phone=whatsappphonenumber/&text=urlencodedtext where whatsappphonenumber is a full phone number in international format and URL-encodedtext is the URL-encoded pre-filled message.
Remove any zeroes, brackets or dashes when adding the phone number in international format. For a detailed explanation on international numbers, read this article.

You can use this functionality to any Salesforce standard and custom objects.


How to convert 15 to 18 digit Id using apex in Salesforce?

Here is the simple way to convert Salesforce 15 digit ID into 18 digit:

String fifteenDigit = '500i0000006oHua'; // Your 15 digit salesforce Id
Id eighteenDigit = fifteenDigit;        
System.debug('15 Digit Id is => ' + fifteenDigit);
System.debug('18 Digit Id is => ' + eighteenDigit);

Output:

15 Digit Id is 500i0000006oHua
18 Digit Id is 500i0000006oHuaAAE



Read More: Which Salesforce API Do I Use in Integration?
                    When To Use Salesforce REST API  
                   When To Use Salesforce SOAP API 
                   When To Use Salesforce Bulk API 
                   When To Use Salesforce Chatter API  

5 Simple Steps to Delete Salesforce Org



I have created a Salesforce Developer org to learn Salesforce functionality. But there is no easy way to reset to default configurations, it seems to delete the current and apply a new one is the easiest solution.

To delete Salesforce developer org, you have to below steps:

1: Go to Setup.
2: Search for "Company Information". 
3: There is a Deactivate Org button in this configuration page, click on it.
4: Enter Your Org Name
5: Click on Deactivate Org Button.

First  30 Days: You can change your mind during this time and reactivate the Org.
Second 30 Days: The org is locked and you must contact Salesforce Customer Support to reactivate it.
After 60 Days: The org is permanently deleted and irretrievable.

The permanent delete takes 60 days. You may reactivate within 30 days and contact support after 30 days but within 60 days.


Read More: Which Salesforce API Do I Use in Integration?
                    When To Use Salesforce REST API  
                   When To Use Salesforce SOAP API 
                   When To Use Salesforce Bulk API 
                   When To Use Salesforce Chatter API  

Select * from X on apex (SOQL) in Salesforce

public static SObject[] selectAll(String objName,  String additionalFilters){
        
        //get object fields
        List<String> fieldList = new List<String>(Schema.getGlobalDescribe()
                               .get(objName).getDescribe().fields.getMap().keySet());
        String fields = String.join(fieldList,',');
        
        return (SObject[])Database.query(
          'SELECT '+fields+' FROM '+objName+ ' '+additionalFilters
        );
    } 
System.debug( Helper.selectAll('Account', 'Order by CreatedDate Limit 10')); 


Read More: Which Salesforce API Do I Use in Integration?
                    When To Use Salesforce REST API  
                   When To Use Salesforce SOAP API 
                   When To Use Salesforce Bulk API 
                   When To Use Salesforce Chatter API  

Skinny Tables Consideration in Salesforce


People sometimes mistake skinny tables as a convenient means of remedying performance issues, but skinny tables might not accommodate all use cases, or improve performance more than reading from the base Salesforce object with efficient indexes. 
They come with “side effects” that you should understand, as they might restrict or burden your business processes.

Before implementing skinny tables, consider the following.

1. Skinny tables are skinny. To ensure optimal performance, they contain only the minimum set of fields required to fulfill specific business use cases. If you later decide to add a field to your report or SOQL query, contact salesforce.com Customer Support to re-create the table.

2. You might think, “Why not just add all the fields at the beginning to get around the previous limitation?” Salesforce.com can add up to only 100 fields, and those fields must be of a certain type. 
For example, formula fields, fields derived from other objects (i.e., through lookup fields), and large CLOB fields cannot be added—if they were, we wouldn’t be calling skinny tables “skinny” at all.

Check out Benefits of Using Skinny Tables In Salesforce here !!!

3. Skinny tables don’t get copied over to sandbox organizations. This limitation might not be an issue for you, but to keep your production and sandbox environments consistent, you must track your changes and work with salesforce.com Customer Support to keep your environments in sync.

4. Skinny tables are custom tables in the underlying Force.com database. They don’t have the dynamic metadata flexibility you find in the base object. If you alter a field type (e.g., change a number field to a text field) the skinny table becomes invalid, and you must contact salesforce.com Customer Support to create a new skinny table.


Read More: Which Salesforce API Do I Use in Integration?
                    When To Use Salesforce REST API  
                   When To Use Salesforce SOAP API 
                   When To Use Salesforce Bulk API 
                   When To Use Salesforce Chatter API  

Benefits of Using Skinny Tables In Salesforce



1. A skinny table is a custom table in the Force.com platform that contains a subset of fields from a standard or custom base Salesforce object. Force.com can have multiple skinny tables, if needed, and maintains them under the hood and keeps them completely transparent to you.

2. By having narrower rows and less data to scan than the base Salesforce object, skinny tables allow Force.com to return more rows per database fetch, increasing throughput when reading from a large object, as this diagram shows.

3. Furthermore, skinny tables do not include soft-deleted rows (i.e., records in the Recycle Bin with isDeleted = true), which could also reduce the table volume in some cases. Custom indexes on the base table are also replicated, and they usually perform better because of the reduced table joins that happen in the underlying database queries.

4. The Force.com platform automatically synchronizes the rows between the base object and the skinny table, so the data is always kept current. The Force.com platform determines at query runtime when it would make sense to use skinny tables, so you don’t have to modify your reports or develop any Apex code or API calls.




Read More: Which Salesforce API Do I Use in Integration?
                    When To Use Salesforce REST API  
                   When To Use Salesforce SOAP API 
                   When To Use Salesforce Bulk API 
                   When To Use Salesforce Chatter API  

When to Use Salesforce Metadata API

Use Metadata API to retrieve, deploy, create, update, or delete customizations for your org. 
The most common use is to migrate changes from a sandbox or testing org to your production environment. 
Metadata API is intended for managing customizations and for building tools that can manage the metadata model, not the data itself.

The easiest way to access the functionality in Metadata API is to use the Force.com IDE or Ant Migration Tool. Both tools are built on top of Metadata API and use the standard Eclipse and Ant tools, respectively, to simplify working with Metadata API.

  • Force.com IDE is built on the Eclipse platform, for programmers familiar with integrated development environments. Code, compile, test, and deploy from within the IDE.
  • The Ant Migration Tool is ideal if you use a script or the command line for moving metadata between a local directory and a Salesforce org.


Read More: Which Salesforce API Do I Use in Integration?
                    When To Use Salesforce REST API  
                   When To Use Salesforce SOAP API 
                   When To Use Salesforce Bulk API 
                   When To Use Salesforce Chatter API  

Which Salesforce API Do I Use in Integration ?

Choosing the right API for your integration needs is an important decision. 
Here’s some information on most commonly used APIs, including supported protocols, data formats, communication paradigms, and use cases. 

Treat this blog as a reference you can return to when you’re considering which API to use.

API Name
Protocol
Data Format
Communication
REST API
REST
JSON, XML
Synchronous
SOAP API
SOAP (WSDL)
XML
Synchronous
Chatter REST API
REST
JSON, XML
Synchronous (photos are processed asynchronously)
User Interface API
REST
JSON
Synchronous
Analytics REST API
REST
JSON, XML
Synchronous
Bulk API
REST
CSV, JSON, XML
Asynchronous
Metadata API
SOAP (WSDL)
XML
Asynchronous
Streaming API
Bayeux
JSON
Asynchronous (stream of data)
Apex REST API
REST
JSON, XML, Custom
Synchronous
Apex SOAP API
SOAP (WSDL)
XML
Synchronous
Tooling API
REST or SOAP (WSDL)
JSON, XML, Custom
Synchronous



Read More: When To Use Salesforce REST API  
                   When To Use Salesforce SOAP API 
                   When To Use Salesforce Bulk API 
                   When To Use Salesforce Chatter API  

When to Use Salesforce Analytics REST API

  • You can access Analytics assets—such as datasets, lenses, and dashboards—programmatically using the Analytics REST API. 
  • Send queries directly to the Analytics Platform. 
  • Access datasets that have been imported into the Analytics Platform. 
  • Create and retrieve lenses.
  • Access XMD information. 
  • Retrieve a list of dataset versions. 
  • Create and retrieve Analytics applications. 
  • Create, update, and retrieve Analytics dashboards. 
  • Retrieve a list of dependencies for an application. 
  • Determine what features are available to the user. 
  • Work with snapshots. 
  • Manipulate replicated datasets.


Read More: When To Use Salesforce REST API  
                   When To Use Salesforce SOAP API 
                   When To Use Salesforce Bulk API 
                   When To Use Salesforce Chatter API  

When to Use Salesforce User Interface API


  • Build Salesforce UI for native mobile apps and custom web apps using the same API that Salesforce uses to build Lightning Experience and Salesforce for Android, iOS, and mobile web. 
  • Build user interfaces that let users work with records, list views, actions, favorites, and more. 
  • Not only do you get data and metadata in a single response, but the response matches metadata changes made to the org by Salesforce admins. 
  • You don’t have to worry about layouts, picklists, field-level security, or sharing—all you have to do is build an app that users love.




Read More: When To Use Salesforce REST API  
                   When To Use Salesforce SOAP API 
                   When To Use Salesforce Bulk API 
                   When To Use Salesforce Chatter API  

When to Use Salesforce Chatter REST API

  • Use Chatter REST API to display Chatter feeds, users, groups, and followers, especially in mobile applications. 
  • Chatter REST API also provides programmatic access to files, recommendations, topics, notifications, Data.com purchasing, and more. 
  • Chatter REST API is similar to APIs offered by other companies with feeds, such as Facebook and Twitter, but it also exposes Salesforce features beyond Chatter.


Read More: When To Use Salesforce REST API  
                   When To Use Salesforce SOAP API  

When to Use Salesforce Bulk API

Bulk API is a specialized RESTful API for loading and querying lots of data at once. By lots, I mean 50,000 records or more. 
Bulk API is asynchronous, meaning that you can submit a request and come back later for the results. 
This approach is the preferred one when dealing with large amounts of data. There are two versions of Bulk API (1.0 and 2.0). 
Both versions handle large amounts of data, but we use Bulk API 2.0 in this module because it’s a bit easier to use.

Bulk API is great for performing tasks that involve lots of records, such as loading data into your org for the first time.

Bulk API is based on REST principles and is optimized for loading or deleting large sets of data. 
You can use it to query, queryAll, insert, update, upsert, or delete many records asynchronously by submitting batches. Salesforce processes batches in the background.

SOAP API, in contrast, is optimized for real-time client applications that update a few records at a time. You can use SOAP API for processing many records, but when the data sets contain hundreds of thousands of records, SOAP API is less practical. Bulk API is designed to make it simple to process data from a few thousand to millions of records.

The easiest way to use Bulk API is to enable it for processing records in Data Loader using CSV files. Using Data Loader avoids the need to write your own client application.

When to Use Salesforce SOAP API

SOAP API is a robust and powerful web service based on the industry-standard protocol of the same name. 
It uses a Web Services Description Language (WSDL) file to rigorously define the parameters for accessing data through the API. 
SOAP API supports XML only. 
Most of the SOAP API functionality is also available through REST API. 
It just depends on which standard better meets your needs.
  • Because SOAP API uses the WSDL file as a formal contract between the API and consumer, it’s great for writing server-to-server integrations.
  • You can use SOAP API to create, retrieve, update, or delete records. You can also use SOAP API to perform searches and much more. 
  • Use SOAP API in any language that supports web services.
For example, you can use SOAP API to integrate Salesforce with your org’s ERP and finance systems. You can also deliver real-time sales and support information to company portals and populate critical business systems with customer information.

                   When To Use Salesforce Analytics REST API 
                   When To Use Salesforce Bulk API 
                   When To Use Salesforce Chatter API  

When to Use Salesforce REST API

REST API is a simple and powerful web service based on RESTful principles. 
It exposes all sorts of Salesforce functionality via REST resources and HTTP methods. 
REST API supports both XML and JSON.

For example, you can create, read, update, and delete (CRUD) records, search or query your data, retrieve object metadata, and access information about limits in your Salesforce org. 

  • Because REST API has a lightweight request and response framework and is easy to use, it’s great for writing mobile and web apps.
  • Its advantages include ease of integration and development, and it’s an excellent choice of technology for use with mobile applications and web projects. 
  • For certain projects, you may want to use REST API with other Salesforce REST APIs. 
  • To build UI for creating, reading, updating, and deleting records, including building UI for list views, actions, and dependent picklists, use User Interface API. 
  • To build UI for Chatter, communities, or recommendations, use Chatter REST API. 
  • If you have many records to process, consider using Bulk API, which is based on REST principles and optimized for large sets of data.

How to use Salesforce Sites Visualforce page in an iFrame on external website

I have implemented Visualforce pages in Force.com Sites. but I have to use that page in 5 different client sites. then what is the possible ways to achieve this?

Workarounds are:

Create 5 different VF pages with specific styling related to each site brand and then share each VF page with a specific team.

Problem: any change in requirements or fields would need to me change every VF page.

Learn Learning Salesforce Lightning Application Development to accelerate your Career with Salesforce!!! 

Best Solution:

Display site's page on external in an iFrame by the following method


  • Goto Setup -> Site settings.
  • Set the "Clickjack Protection Level" to "Allow framing by any page (no protection)".- same like below image.
  • Press "Save" button.

Difference between component.find() component.get() in Salesforce Lightning

component.find()

Find the button component by calling cmp.find("button1") in your client-side controller, where cmp is a reference to the component containing the button.

Syntax: component.find("auraid");

find() returns different types depending on the result.

  1. If the local ID is unique, find() returns the component.
  2. If there are multiple components with the same local ID, find() returns an array of the components.
  3. If there is no matching local ID, find() returns undefined.
component.get()

Returns the value referenced using property syntax. 

Syntax: component.get(String key) 

For example, cmp.get("v.attr") returns the value of the attr aura:attribute.

Learn Learning Salesforce Lightning Application Development to accelerate your Career with Salesforce!!! 

Full Example:



Lightning Component:



<aura:component >
    <aura:attribute name="LighningPageProperty" type="String" default="Demo"/>
    <aura:handler name="init" value="this" action="{!c.doInit}"/>
    <ui:inputText aura:id="inputComponent" class="slds-input" value="{!v.LighningPageProperty}" />
    <ui:inputText aura:id="auraid" class="slds-input"/>    
</aura:component>

Lightning Controller: 

({
    doInit : function(component, event, helper) {
        component.find("auraid").set("v.value", "Search Example");
        component.set("v.LighningPageProperty", "Find Example");
        var val = component.get("v.LighningPageProperty"); 
    },    
})