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
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
- 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?
- QueryResult = connection.query(string queryString);
- String soqlQuery = "SELECT FirstName, LastName FROM Contact";
- qResult = binding.query(soqlQuery);
QueryAll()-
- QueryResult = connection.queryAll(string queryString);
- String soqlQuery = "SELECT Name, IsDeleted FROM Account";
- QueryResult qr = binding.queryAll(soqlQuery);
QueryMore()-
- QueryResult = connection.queryMore( QueryLocator QueryLocator);
- String soqlQuery = "SELECT FirstName, LastName FROM Contact";
- qResult = connection.query(soqlQuery);
- qResult = connection.queryMore(qResult.getQueryLocator());
There are below methods are useful while doing the incremental process
getDeleted()
- 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.- GetUpdatedResult[] = connection.getUpdated(string sObjectType, dateTime startDate, dateTime EndDate);
search()
- SearchResult = connection.search(String searchString);
- SearchResult sr = connection.search(
- "FIND {4159017000} IN Phone FIELDS RETURNING "
- + "Contact(Id, Phone, FirstName, LastName), "
- + "Lead(Id, Phone, FirstName, LastName), "
- + "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.- sObject[] result = connection.retrieve(string fieldList, string sObjectType, ID ids[]);
- 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.
- QueryOptions qo = new QueryOptions();
- qo.batchSize = 250;
- qo.batchSizeSpecified = true;
- binding.QueryOptionsValue = qo;
How is batch-processed?
What are the data manipulation methods?
Create()
- SaveResult[] = connection.create(sObject[] sObjects);
Example
- Opportunity newOpportunity = new Opportunity();
- newOpportunity.Name = "OpportunityWithFK";
- newOpportunity.StageName = "Prospecting";
- DateTime dt = (DateTime)binding.getServerTimestamp().timestamp;
- newOpportunity.CloseDate = dt.AddDays(7);
- newOpportunity.CloseDateSpecified = true;
- SaveResult[] results = connection.create(new sObject[] {newOpportunity });
Update()
- SaveResult[] = connection.update(sObject[] sObjects);
- Opportunity updateOpportunity = new Opportunity();
- updateOpportunity.setId(oppId);
- updateOpportunity.setStageName("Qualification");
- SaveResult[] results = connection.update(new SObject[] { updateOpportunity });
Upsert()
- UpsertResult[] = connection.upsert(String externalIdFieldName, sObject[] sObjects);
- Opportunity newOpportunity = new Opportunity();
- newOpportunity.Name = "UpsertOpportunity";
- newOpportunity.StageName = "Prospecting";
- DateTime dt = (DateTime)binding.getServerTimestamp().timestamp;
- newOpportunity.CloseDate = dt.AddDays(7);
- newOpportunity.CloseDateSpecified = true;
- newOpportunity.MyExtId__c = "UPSERTID001";
- SaveResult[] results = binding
- .upsert("MyExtId", new sObject[] { newOpportunity });
No comments:
Post a Comment