Beruflich Dokumente
Kultur Dokumente
The different Types of Salesforce APIs are mentioned below and you can also get the same info from
Salesforce Help material. My intention is to help newbies with Real Time Example which I
explained Below..
SOAP API
Use SOAP API to create, retrieve, update or delete records, such as accounts, leads, and custom objects.
With more than 20 different calls, SOAP API also allows you to maintain passwords, perform searches,
and much more. Use SOAP API in any language that supports Web services.
REST API
REST API provides a powerful, convenient, and simple REST-based Web services interface for
interacting with Salesforce. Its advantages include ease of integration and development, and its an
excellent choice of technology for use with mobile applications and Web projects. However, if you have a
large number of records to process, you may wish to use Bulk API, which is based on REST
principles and optimized for large sets of data.
Bulk API
Bulk API is based on REST principles and is optimized for loading or deleting large sets of data. You can
use it to query, insert, update, upsert, or delete a large number of records asynchronously by submitting
batches which are processed in the background by Salesforce.
SOAP API, in contrast, is optimized for real-time client applications that update small numbers of
records at a time. Although SOAP API can also be used for processing large numbers of records, when
the data sets contain hundreds of thousands of records, it becomes less practical. Bulk API is designed to
make it simple to process data from a few thousand to millions of records.
Metadata API
Use Metadata API to retrieve, deploy, create, update, or delete customizations for your organization.
The most common use is to migrate changes from a sandbox or testing organization 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.
Apex
Use Apex if you want to:
Create custom transactional logic (logic that occurs over the entire transaction, not just with a
single record or object).
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 Developers Guide.
Visualforce
Visualforce
Define navigation patterns and data-specific rules for optimal, efficient application interaction.
REST-style architectures consist of clients and servers. Clients initiate requests to servers; servers
process requests and return appropriate responses. Requests and responses are built around the
transfer of representations of resources.
The Force.com REST API provides you with a powerful, convenient, and simple Web services API for
interacting with Force.com. Its advantages include ease of integration and development, and it is an
excellent choice of technology for use with mobile applications and Web 2.0 projects. However, if you
have large numbers of records to process, you may wish to use Bulk API, which is based on REST
principles and optimized for large sets of data.
Example: Create as Apex class with Below code(EMP Object should be created in
beginning).
@RestResource(urlMapping=/EMPLOYEE__c/*)
global with sharing class sampleRest
{
@HttpDelete
global static void doDelete()
{
RestRequest req = RestContext.request;
RestResponse res = RestContext.response;
String memberId = req.requestURI.substring(req.requestURI.lastIndexOf(/)+1);
EMPLOYEE __c emp = [SELECT Id FROM EMPLOYEE__C WHERE Id = :EMPId];
delete EMP;
}
@HttpGet
global static EMPLOYEE __c doGet()
{
RestRequest req = RestContext.request;
RestResponse res = RestContext.response;
String memberId = req.requestURI.substring(req.requestURI.lastIndexOf(/)+1);
EMPLOYEE __c result = [SELECT Id, Name FROM EMPLOYEE __c WHERE Id =
:EMPId];
return result;
}
@HttpPost
global static String doPost(String name)
{
EMPLOYEE __c m = new EMPLOYEE __c();
e.Name = name;
insert e;
return e.Id;
}
The Web Services Description Language (WSDL) is an XML-based interface description language that
is used for describing the functionality offered by a Web Service.
WSDL have to be downloaded from this location. We need this WSDL in later part of this tutorial.
Once, WSDL is downloaded and saved on local drive. We have to go to Salesforce and navigate
to Setup | Develop | Apex Classes. On right hand side, you will find button named as Generate
from WSDL. This button will generate equivalent Apex class to support Webservice call. In some
Programming languages, these classes are known as Proxy classes or Stubs.
When we click on Generate from WSDL button, it will prompt for WSDL File. Select WSDL
file downloaded previously and click on Parse WSDL button. On next page you will get this
error : Failed to parse wsdl: Found more than one wsdl:portType. WSDL with multiple
portType not supported.
In some cases you may also get error like : Failed to parse wsdl: Found more than one
wsdl:binding. WSDL with multiple binding not supported.
Intentionally, I have used this WSDL to explain that currently Salesforce supports only single portType
and binding.
PortType : defines a web service, the operations that can be performed, and the messages that are
involved.
Binding : WSDL bindings defines the message format and protocol details for a web service.
Reason, we are getting an error because wsdltoApex doesnt support multiple PortType, Binding,
SOAP 1.2 and Schema imports. You can read more here from Salesforce documentation.
How to resolve multiple portType and Binding error in Apex while generating stubs ?
We have to modify downloaded WSDL to make sure it only contains Single Binding and single
PortType. Before modifying I would suggest to read about WSDL elements. I have uploaded both
versions of WSDL (Please change attached file extensions from txt to xml). First one is Actual WSDL and
second I have modified to remove errors. You can compare both and check how I removed multiple
PortType and Binding elements from WSDL.
Before trying to use webservice, we have to inform Salesforce that our code will try to get some Data
from External source (rather interact with external system). And therefore Remote Site Setting comes
into picture.
Create new Site setting for URL http://www.webservicex.net. If we skip this step, we will endup with
error like Unauthorized Endpoint.
We can use generated Apex class in Visualforce or some other location. To keep this tutorial simple, I am
using Developer Console. Open Developer Console and press Ctrl+E.
wwwWebservicexNet.StockQuoteSoap proxyClass =
newwwwWebservicexNet.StockQuoteSoap();
System.debug(retVal);
In above code CTSH is Stock symbol for Cognizant Technology Solution. You can use any other valid
Stock Symbol. Output will be visible in Console Log. We can use this output as per our need
As shown in above code, I have created Object for wwwWebservicexNet.StockQuoteSoap. I was able
to identify that which class to instantiate? I was able to identify by port type element name from WSDL.
You may get Timeout exception while calling webservice. Default time is 10sec (At time of writing this
tutorial, may change in future release). we can use timeout_x property to increase time to wait for
response from web service. So above code can be re-written as
wwwWebservicexNet.StockQuoteSoap proxyClass =
newwwwWebservicexNet.StockQuoteSoap();
System.debug(retVal);
In above code CTSH is Stock symbol for Cognizant Technology Solution. You can use any other valid
Stock Symbol. Output will be visible in Console Log. We can use this output as per our need
You may get Timeout exception while calling webservice. Default time is 10sec (At time of writing this
tutorial, may change in future release). we can use timeout_x property to increase time to wait for
response from web service. So above code can be re-written as
wwwWebservicexNet.StockQuoteSoap proxyClass =
newwwwWebservicexNet.StockQuoteSoap();
proxyClass.timeout_x = 20000 ; // timeout in milliseconds
String retVal = proxyClass.GetQuote(CTSH);
System.debug(retVal);