About Me

My photo
PLANO, Texas, United States

Thursday, September 17, 2020

SOAP API

SOAP API allows an external system to connect to salesforce to manipulate data and processes. The SOAP exposes to the external systems: 

  • Standard salesforce object including custom field
    • Custom sObject
    • sObject metadata
  • Using the SOAP API:
    • Perform DML on data
    • Query and search the data
    • Work with the approval process
    • Create and update sharing records
  • It uses WSDL (Web service Description language) to communicate with the external system. WSDL defines the protocol to use for exchanging information (SOAP). 
  • Two types of WSDL file is provided by Salesforce
    • Enterprise WSDL
    • Partner WSDL
  • SOAP API calls are synchronous
Usage the API have usage limit-

Due to the multi-tenant and on-demand nature of salesforce, there are limits enforced on API usage as below:

  • Concurrent API limit
  • Total API Limit
Working with Partner WSDL-

  • More flexible, metadata-driven approach to integration
  • Flexible at runtime rather than design time
  • No need to change WSDL if any metadata got changes in CRM as it work on sObject
  • Uses generic sObject rather than object-specific classes like AVC__c etc

Enterprise vs Partner WSDL-










What methods are available to get data?







Query()-

Executes a query against the specified object and returns data that matches the specified criteria.
Syntax

  1. QueryResult = connection.query(string queryString);

Example

  1. String soqlQuery = "SELECT FirstName, LastName FROM Contact";
  2. qResult = binding.query(soqlQuery);

QueryAll()-

Retrieves data from specified objects, including deleted data.
Syntax -queryString is passed as an argument

  1. QueryResult = connection.queryAll(string queryString);
Example-

  1. String soqlQuery = "SELECT Name, IsDeleted FROM Account";
  2. QueryResult qr = binding.queryAll(soqlQuery);

QueryMore()-

Use queryMore() to request additional results from a previous query() call. If your initial query() call returns more than 2000 results, you can use queryMore() to query for the additional results.  This SOAP API reference describes this call.

The argument queryLocator is passed from the query() function.
Syntax-

  1. QueryResult = connection.queryMore( QueryLocator QueryLocator);

Example

  1. String soqlQuery = "SELECT FirstName, LastName FROM Contact";
  2. qResult = connection.query(soqlQuery);
  3. qResult = connection.queryMore(qResult.getQueryLocator());

There are below methods are useful while doing the incremental process

getDeleted()

Retrieves the list of individual records that have been deleted within the given timespan for the specified object.
Syntax-

  1. GetDeletedResult = connection.getDeleted(string sObjectType, dateTime startDate, dateTime EndDate);

getUpdated()

Retrieves the list of individual records that have been updated (added or changed) within the given timespan for the specified object.
Syntax-

  1. GetUpdatedResult[] = connection.getUpdated(string sObjectType, dateTime startDate, dateTime EndDate);

search()

Executes a text search in your organization’s data.

Syntax

  1. SearchResult = connection.search(String searchString);

Example

  1. SearchResult sr = connection.search(
  2. "FIND {4159017000} IN Phone FIELDS RETURNING "
  3. + "Contact(Id, Phone, FirstName, LastName), "
  4. + "Lead(Id, Phone, FirstName, LastName), "
  5. + "Account(Id, Phone, Name)");

retrieve()

Use the retrieve() call to retrieve individual records from an object. The client application passes the list of fields to retrieve, the object, and an array of record IDs to retrieve. The retrieve() call does not return records that have been deleted.

Syntax

  1. sObject[] result = connection.retrieve(string fieldList, string sObjectType, ID ids[]);

Example

  1. SObject[] sObjects = connection.retrieve("ID, Name, Website","Account", ids);

How does batching work with the query?

  • Query batch sizes:
    • The default is 500
    • the minimum is 200
    • maximum is 2,000. 
  • There is no guarantee that the requested batch size requested is the actual batch size; changes are sometimes made to maximize performance.
  • Use QueryOptions to specify the batch size.
  1. QueryOptions qo = new QueryOptions();
  2. qo.batchSize = 250;
  3. qo.batchSizeSpecified = true;
  4. binding.QueryOptionsValue = qo;

How is batch-processed?








What are the data manipulation methods?







Create()

Adds one or more new records to your organization’s data.
Syntax

  1. SaveResult[] = connection.create(sObject[] sObjects);

Example

  1. Opportunity newOpportunity = new Opportunity();
  2. newOpportunity.Name = "OpportunityWithFK";
  3. newOpportunity.StageName = "Prospecting";
  4. DateTime dt = (DateTime)binding.getServerTimestamp().timestamp;
  5. newOpportunity.CloseDate = dt.AddDays(7);
  6. newOpportunity.CloseDateSpecified = true;
  7. SaveResult[] results = connection.create(new sObject[] {newOpportunity });

Update()

Use this call to update one or more existing records, such as accounts or contacts, in your organization’s data.
Syntax-

  1. SaveResult[] = connection.update(sObject[] sObjects);

Example

  1. Opportunity updateOpportunity = new Opportunity();
  2. updateOpportunity.setId(oppId);
  3. updateOpportunity.setStageName("Qualification");
  4. SaveResult[] results = connection.update(new SObject[] { updateOpportunity });

Upsert()

Upsert is a merging of the words insert and update. This call is available for objects if the object has an external ID field or a field with the idLookup field property.
Syntax

  1. UpsertResult[] = connection.upsert(String externalIdFieldName, sObject[] sObjects);
Example

  1. Opportunity newOpportunity = new Opportunity();
  2. newOpportunity.Name = "UpsertOpportunity";
  3. newOpportunity.StageName = "Prospecting";
  4. DateTime dt = (DateTime)binding.getServerTimestamp().timestamp;
  5. newOpportunity.CloseDate = dt.AddDays(7);
  6. newOpportunity.CloseDateSpecified = true;
  7. newOpportunity.MyExtId__c = "UPSERTID001";
  8. SaveResult[] results = binding
  9. .upsert("MyExtId", new sObject[] { newOpportunity });

To know about other integration API at a glance, pls Click here

No comments:

Post a Comment