Blog

Once you start working in the Salesforce world, it won’t take long until you come across the need to integrate or connect your Salesforce org to an internal or external system. At that point, you will start to hear about API’s. While you may think that is something that only developers need to know and understand it is useful for anyone working with Salesforce to know what they are and how they work, at least at a high level.

API stands for Application Program Interface. Salesforce APIs are a way for other applications (or code in other applications) to programmatically access data within your Salesforce org, in a simple and secure manner. Salesforce can also call APIs to retrieve data from other systems or services, but here we are going to just cover the Salesforce APIs that allow access to Salesforce data. Imagine it to be a door for data to flow in and out of your Salesforce org. You can interact with your Salesforce data via the user interface and via an API.

API Fact: You must have used Dataloader to push and retrieve data from your Salesforce org. Well, Dataloader sends and receives data through one such door (APIs).

Salesforce offers multiple kinds of APIs (different types of doors that is), for the data to move through. They are:

  • SOAP API
  • REST API
  • Apex REST API
  • Apex SOAP API
  • Bulk API
  • Metadata API
  • Chatter REST API
  • Streaming API
  • Tooling API

Each of these APIs has specific uses, for which they are built for. We are going to cover the two elementary APIs – SOAP API and REST API.

SOAP API

SOAP stands for Simple Object Access Protocol, and is an XML based messaging protocol. It is one of the most common integration methodology that you would see in large enterprises, as SOAP has been around for a long time, and many legacy applications support only SOAP integrations. It is also useful to understand the concept of WSDL (Web Service Description Language), which is an XML document that is used to describe and define a SOAP web service request.

Salesforce supports data integration through its proprietary Force.com SOAP API, and lets you do create, retrieve, update and delete operations to Salesforce data from an external application. Salesforce provides 2 kinds of WSDLs:

  • Enterprise Web Services WSDL, and
  • Partner Web Services WSDL

As the name suggests, Enterprise WSDLs are intended for Salesforce customers and their ISVs, to build integrations specific to their own Salesforce Org. Whereas the Partner WSDL is intended for App development partners, with which a generic integration can be authored that can work with multiple Salesforce orgs.

Let us take a look at one of the enterprise WSDLs. Navigate to Setup | Develop | APIs to see this screen:

Notice the link to generate Enterprise WSDL. Clicking on this link, would generate the enterprise WSDL for you, and it should look something like this:

You would use this to author your SOAP integrations. This can be used with any external application that is capable of sending and receiving SOAP based Web Service request. Let’s see how.

Save the enterprise WSDL that you just generated, as an XML file on your hard disk. Then, from the SOAP UI application (http://www.soapui.org/) load this, to create a new SOAP project. Once done, navigate to the Login tag, and create a Request. Fill in your User name and password (which needs to be appended with your security key), and submit the request. Your screen would appear like this:

This is a request-response dialogue. In the left hand side you would find the request submitted, which was a simple request for logging in; and on the right hand side you would see the response received. This is what Salesforce return as an answer to your request. Since our request was a login request, the response contains a Session ID, which shows that login was successful.

This is a simple representation of how a SOAP request works. An application which is capable of sending, receiving and understanding SOAP requests can use such requests to read and manipulate data within Salesforce.

REST API

Now let us move to see the second main type of API provided by Salesforce – the Force.com REST API. REST stands for Representational State Transfer, which is considered to be a light weight alternative to SOAP, and therefore preferred by modern web & mobile based applications. The primary difference here is that requests are sent as an HTTP request, rather than a SOAP request.

For instance, a sample REST request for querying all account IDs and account names would look like this:

https://na2.salesforce.com/services/data/v20.0/query?q=SELECT+id,name+from+Account

The response can be received as an XML format or as a JSON (Java Script Object Notation) format. We have already seen what an XML response format looks like. Shown below is how a JSON response format would look like:

{

   “Id” : “00423200000as7kAAI”,

   “Name” : “Acme”,

}

 

Let’s try it out. While you could use SOAP UI or chrome POSTMAN plugin to REST services, here I am going to use Workbench. Open Workbench and log in to your Salesforce instance. In the Utilities section, choose REST Explorer to bring up a screen as shown below.

 

Clicking the Execute button would bring up all the available resources that Salesforce offers.

 

Let us do a query on Account for name and ID. All you need to do is pass the right SOQL statement as a query parameter for GET method. All the spaces in the SOQL statement would need to be replaced by a + sign. Once you have the query constructed, click execute to get the results as shown:

 

Take a moment to click the “Show Raw Response” URL to see the actual JSON response in the format mentioned above. Workbench intelligently displays this in a consumable format for human use, and hence you don’t see the JSON response by default.

Notice the various methods like GET, POST, PUT, PATCH, etc available, which can be used along with your Force.com REST API. The methods translate to :

GET = READ

POST = CREATE

PUT / PATCH = UPDATE

DELETE = DELETE

Here is an example of a POST, using the standard Account Rest API. The request body contains a JSON request, in this case to create an account, it contains values for the Name and Phone fields. After pressing the Execute button, the response is returned below. In this case the request was successful, and returned the id of the newly created Account.

rest-response

Here is the account that was created  ‘REST Account’, with the phone value provided in the JSON request body.

rest-account

Here is another example using the PATCH method to update the Account Id custom field in the same Account record we just created. Notice that the URI has the record id appended.

rest-patch_001

Here is the record after update.

patch-update-custom-field

Besides the different protocols they use to send and receive data, the other differences between the APIs are:

  • SOAP API is more highly structured and strongly typed than REST API
  • SOAP API is better in situations where there is a large volume of data that need to be transferred.
  • SOAP APIs are usually used in large enterprises with a legacy application backbone
  • REST API is good in cases where it has to work together with JavaScript, which usually occurs when you are using it to access Salesforce data from Web or Mobile applications.
  • REST APIs are used for modern web & mobile application development

 

 

What Certification are you studying for now?

Focus on Force currently provides practice exams and study guides for sixteen certifications

An introduction to Salesforce APIs

Once you start working in the Salesforce world, it won’t take long until you come across the need to integrate or connect your Salesforce org to an internal or external system. At that point, you will start to hear about API’s. While you may think that is something that only developers need to know and understand it is useful for anyone working with Salesforce to know what they are and… Read More

An introduction to Salesforce APIs

Getting Started with Salesforce Entitlements

When a customer calls and requests support, how does a business know if and what level of service they are entitled to? Or what if service is only provided on certain products? Service could be provided for a certain period (e.g. a warranty) and then a customer must pay for service beyond the warranty period. It could also be that customers can purchase extended warranties or service contracts that may… Read More

Getting Started with Salesforce Entitlements

Winter 16 is Coming

Winter is Coming… While you are pondering over deploying the new Summer ’15 features, here is more news. The plan for Salesforce Winter ’16 release is out. It is time to plan your registrations for getting a sandbox preview of Winter ’16 features as and when it becomes available. You would need to take action before September 4, 2015 in case you are planning to make your Sandbox part of… Read More

Winter 16 is Coming

Native Duplicate Management in Salesforce

Administrators (and developers) are often faced with the task of cleaning up duplicate data from an org. Contact and Lead objects are the usual suspects for duplicate data. Anyone who has made an attempt at cleaning up duplicate data would agree it is a daunting and quite unenviable task. Duplicate data weighs down on your employee performance, application usability, risks customer satisfaction, and skews analytics. So, it is a priority… Read More

Native Duplicate Management in Salesforce

Salesforce Multi Org Dilemma

What exactly is a Salesforce org? The Salesforce document glossary describes an org (or Organization), as “A deployment of Salesforce with a defined set of licensed users. An organization is the virtual space provided to an individual customer of Salesforce. Your organization includes all of your data and applications, and is separate from all other organizations.” So, what is a multi-org situation? The multi-org situation that I refer to in… Read More

Salesforce Multi Org Dilemma

Salesforce Lightning Connect Example

Unlocking Back Office Data through Salesforce Lightning Connect The general approach to enterprise programming is changing. Significant investments are being made in making enterprise IT applications agile and nimble. Salesforce, being the innovators they are, have taken significant strides in this direction. One such move is the introduction of the lightning framework – a philosophy pioneered to reduce the time in developing and deploying enterprise applications. For any enterprise system… Read More

Salesforce Lightning Connect Example

Salesforce Process Builder Example

Lightning Process Builder – Point & Click Process Definition in the Cloud  The Spring ’15 release of Salesforce has opened up a whole new philosophy of developing in the cloud – the lightning framework. One key element of the lightning framework is the Lightning Process Builder. Before diving into Lightning Process Builder, it is good to understand where Salesforce is going with the entire “Lightning” idea. It is positioned as… Read More

Salesforce Process Builder Example

Salesforce Email to Case Setup Example

Email to Case is a standard Salesforce feature that allows cases to be created from emails.  We will be looking into the detail of On-Demand Email-To-Case and Email Services.On Demand Email-To-CaseThe first question when considering this functionality maybe which email address should be used to send to? We cannot send email to just any email address and have a Salesforce case created. We need to generate it using Salesforce configuration.Go… Read More

Salesforce VLOOKUP Example

Many people are aware of the Microsoft Excel vlookup function, that will return a value in a table (or defined range of cells) based on an identifier. Salesforce has a function with the same name, and this post will explain how it can be used using an example.Let’s say that you have a business requirement that only cases that have been open for a certain period of time can be… Read More

Salesforce VLOOKUP Example

Salesforce Multiple Record Types Example

Creating Multiple Record Types Creating brand new custom objects in Salesforce, while necessary, can be time consuming and tedious. Often times you will need to create a different page layout or new selections for a particular picklist field but the only way you know how to do this is create an entirely different custom object and customize it as needed. This is where creating multiple record types for one object… Read More

Salesforce Multiple Record Types Example

Creating a Dynamic Dashboard in Salesforce

Dashboards are a great way to represent data visually within an organization. They can show how you have performed in the past and what’s happening at the moment – two keys to any business that wants to be successful.Normally, dashboards in Salesforce are run based on one user for the entire organization. Meaning the dashboard looks the same for all users within the organization. This is great if you are… Read More

Creating a Dynamic Dashboard in Salesforce

Salesforce Web to Lead

The Salesforce Web to Lead functionality offers an easy way to get leads from your website into Salesforce. Although there are some constraints with its use, it will satisfy the requirements for many organizations. Salesforce also offers a way to associate the leads from the webpage to a particular campaign. You can also have multiple web-to-lead forms from multiple websites or landing pages, all inserting leads in Salesforce and either… Read More

Salesforce Web to Lead

Reporting on Accounts that haven’t ordered a product in the last 12 months

It is quite common for organizations to bring order history into Salesforce to add to other interactions captured in Salesforce to have a complete picture of a customer. Once the information has been brought into Salesforce, it is easy to report on account order history, but what if you would like to report on accounts that don’t have order history for a particular product in the last 12 months. This… Read More

Reporting on Accounts that haven’t ordered a product in the last 12 months

Reporting by Month and Year with Salesforce Reports

You may have the requirement to report by month and year. If you have tried that, you will find that the standard reporting features may not provide you with what you are looking for. Lets say that you would like to report on the number of closed opportunities over the last 3 years. You would like to have months reported along the top in columns and the years down the… Read More

Reporting by Month and Year with Salesforce Reports