![Page 1: Building towards a Composite API Framework in Salesforce](https://reader031.vdocuments.site/reader031/viewer/2022030309/58f1a32c1a28abe4298b463f/html5/thumbnails/1.jpg)
Building towards a Salesforce Composite API
Jay Hurst
Director, Product Management
@extraidea
Abhinav Chadda
SMTS – Enterprise API
@abhinavchadda
![Page 2: Building towards a Composite API Framework in Salesforce](https://reader031.vdocuments.site/reader031/viewer/2022030309/58f1a32c1a28abe4298b463f/html5/thumbnails/2.jpg)
Safe Harbor
Safe harbor statement under the Private Securities Litigation Reform Act of 1995:
This presentation may contain forward-looking statements that involve risks, uncertainties, and assumptions. If any such uncertainties materialize
or if any of the assumptions proves incorrect, the results of salesforce.com, inc. could differ materially from the results expressed or implied by the
forward-looking statements we make. All statements other than statements of historical fact could be deemed forward-looking, including any
projections of product or service availability, subscriber growth, earnings, revenues, or other financial items and any statements regarding
strategies or plans of management for future operations, statements of belief, any statements concerning new, planned, or upgraded services or
technology developments and customer contracts or use of our services.
The risks and uncertainties referred to above include – but are not limited to – risks associated with developing and delivering new functionality for
our service, new products and services, our new business model, our past operating losses, possible fluctuations in our operating results and rate
of growth, interruptions or delays in our Web hosting, breach of our security measures, the outcome of any litigation, risks associated with
completed and any possible mergers and acquisitions, the immature market in which we operate, our relatively limited operating history, our ability
to expand, retain, and motivate our employees and manage our growth, new releases of our service and successful customer deployment, our
limited history reselling non-salesforce.com products, and utilization and selling to larger enterprise customers. Further information on potential
factors that could affect the financial results of salesforce.com, inc. is included in our annual report on Form 10-K for the most recent fiscal year
and in our quarterly report on Form 10-Q for the most recent fiscal quarter. These documents and others containing important disclosures are
available on the SEC Filings section of the Investor Information section of our Web site.
Any unreleased services or features referenced in this or other presentations, press releases or public statements are not currently available and
may not be delivered on time or at all. Customers who purchase our services should make the purchase decisions based upon features that are
currently available. Salesforce.com, inc. assumes no obligation and does not intend to update these forward-looking statements.
![Page 5: Building towards a Composite API Framework in Salesforce](https://reader031.vdocuments.site/reader031/viewer/2022030309/58f1a32c1a28abe4298b463f/html5/thumbnails/5.jpg)
Building Streamlined APIs
Many customers are facing a set of challenges around building
client applications against the Salesforce REST API.
Raise your hand if you:
• Have used the REST API in Salesforce
• Have tried to build a client application using the REST API but have
faced issues with the number of round trips
• Have a need to design efficient APIs and want to reduce the number of
API round trips to the Salesforce server
![Page 6: Building towards a Composite API Framework in Salesforce](https://reader031.vdocuments.site/reader031/viewer/2022030309/58f1a32c1a28abe4298b463f/html5/thumbnails/6.jpg)
What is the Enterprise API?
![Page 7: Building towards a Composite API Framework in Salesforce](https://reader031.vdocuments.site/reader031/viewer/2022030309/58f1a32c1a28abe4298b463f/html5/thumbnails/7.jpg)
Salesforce1 Enterprise APIsThe Salesforce “Data” APIs
• Allow programmatic access to your salesforce data through various API technologies
• Many different APIs to suit your specific needs
Rest APIs
Access and manipulate data with a RESTful pattern with JSON and XML
payloads
Soap APIs
Access and manipulate data using SOAP.
StreamingAPIs
Subscribe to updates using a Bayeux / CometD HTTP Streaming API.
Bulk APIs
Perform Bulk Queries and Inserts/Updates Asynchronously.
![Page 8: Building towards a Composite API Framework in Salesforce](https://reader031.vdocuments.site/reader031/viewer/2022030309/58f1a32c1a28abe4298b463f/html5/thumbnails/8.jpg)
Comprehensive Suite of APIs and Toolkits
Web Service
Endpoint
Web Service
Endpoint
Apex
WS/REST
Outbound
Messaging
Business Logic
Sync Bulk API
Streaming
API Topic
CRUD
Data
Bayeux
Client
Applications and Middleware
Java SDK Ruby gemPHP
Toolkit
Mobile
SDK
Mobile
SDK
3rd Party
Adapters
Apex
Callouts
![Page 9: Building towards a Composite API Framework in Salesforce](https://reader031.vdocuments.site/reader031/viewer/2022030309/58f1a32c1a28abe4298b463f/html5/thumbnails/9.jpg)
What is a Composite API?
![Page 10: Building towards a Composite API Framework in Salesforce](https://reader031.vdocuments.site/reader031/viewer/2022030309/58f1a32c1a28abe4298b463f/html5/thumbnails/10.jpg)
What is a Composite API?
• An API that is built by combining existing API functions
• A single request to an API can perform multiple functions
• Orchestration of the composite APIs allow developer
controlled business logic and functionality
• Responses from one API method can be directed as inputs into another method
• Multiple APIs can be used in a single call to improve performance
• Compositions are key for designing efficient API for use in
mobile development
![Page 11: Building towards a Composite API Framework in Salesforce](https://reader031.vdocuments.site/reader031/viewer/2022030309/58f1a32c1a28abe4298b463f/html5/thumbnails/11.jpg)
Salesforce Composite Resources
![Page 12: Building towards a Composite API Framework in Salesforce](https://reader031.vdocuments.site/reader031/viewer/2022030309/58f1a32c1a28abe4298b463f/html5/thumbnails/12.jpg)
Batching REST Resource
• Resource which accepts multiple REST calls to execute
• A single Batch REST request can execute up to 25 sub-requests
• Sub-requests contains the resource (URI) and the method to execute
• Each sub-request is an unrelated API call
• Sub-requests are executed serially, in order, and as the running user
• As each sub-request completes, the call is committed
• Has one optional parameter
• haltOnError - indicates if the batch should stop on any error that is encountered
• The response will be a JSON object of responses from the sub
requests
![Page 13: Building towards a Composite API Framework in Salesforce](https://reader031.vdocuments.site/reader031/viewer/2022030309/58f1a32c1a28abe4298b463f/html5/thumbnails/13.jpg)
Traditional REST API Diagram
![Page 14: Building towards a Composite API Framework in Salesforce](https://reader031.vdocuments.site/reader031/viewer/2022030309/58f1a32c1a28abe4298b463f/html5/thumbnails/14.jpg)
Batch REST API Diagram
![Page 15: Building towards a Composite API Framework in Salesforce](https://reader031.vdocuments.site/reader031/viewer/2022030309/58f1a32c1a28abe4298b463f/html5/thumbnails/15.jpg)
Example Batch Request
{"batchRequests" : [
{"method" : "POST",
"url" : "v34.0/sobjects/account/",
"richInput" : {"Name" : "NewName", "Industry" : "Tech"}},
{"method" : "GET",
"url" : "v34.0/sobjects/account/describe/"},
{"method" : "GET",
"url" : "v34.0/query?q=select id, name, industry from account order by
createddate desc limit 10"
}]
}
![Page 16: Building towards a Composite API Framework in Salesforce](https://reader031.vdocuments.site/reader031/viewer/2022030309/58f1a32c1a28abe4298b463f/html5/thumbnails/16.jpg)
Example Successful Batch Response
{"hasErrors" : false,
"results" : [{
"statusCode" : 201,
"result": {"id" : "001B0000003xiArIAI”, "success" : true, "errors" : [ ]}
}, {
"statusCode" : 200,
"result": {"actionOverrides" : [ ], "activateable" : false, ...,
"undeletable" : true, "updateable" : true}
},{
"statusCode" : 200,
"result": {"totalSize" : 10, "done" : true,
"records" : [{
"attributes" : {"type" : "Account”, "url" : "/services/data/v34.0/
sobjects/Account/001B0000003xiArIAI”},
...
}]
}
}]
}
![Page 17: Building towards a Composite API Framework in Salesforce](https://reader031.vdocuments.site/reader031/viewer/2022030309/58f1a32c1a28abe4298b463f/html5/thumbnails/17.jpg)
Example Unsuccessful Batch Response
{"hasErrors" : true,
"results" : [{
"result" : [{"message" : "Required fields are missing: [Name]”,"errorCode" :
"REQUIRED_FIELD_MISSING",
"fields" : [ "Name" ]}],
"statusCode" : 400
},{
"result”:[{"message”:"Cannot access this resource in a batch request”,
"errorCode”: "INVALID_BATCH_REQUEST”}],
"statusCode" : 400
},{
"result" : [{
"message" : "\nselect ids, name, industry from account\n^\nERROR at Row:
1:Column:8\nNo such column 'ids' on entity 'Account'. If you are
attempting to use a custom field, be sure to append the
'__c' after the custom field name. Please reference your WSDL or
the describe call for the appropriate names.”, "errorCode" :
"INVALID_FIELD"}],
"statusCode" : 400
}]}
![Page 18: Building towards a Composite API Framework in Salesforce](https://reader031.vdocuments.site/reader031/viewer/2022030309/58f1a32c1a28abe4298b463f/html5/thumbnails/18.jpg)
Batching REST API Demo
![Page 19: Building towards a Composite API Framework in Salesforce](https://reader031.vdocuments.site/reader031/viewer/2022030309/58f1a32c1a28abe4298b463f/html5/thumbnails/19.jpg)
TreeSave REST Resource
• Creates SObject trees with the same top level object type
• A recursive data structure that contains a root record, its data, and its
child records represented as other sObject trees
• The REST resource manages all of the ID creations and mapping
• Create an Account, Contact, Opportunity, and Note in a single call
• The request can contain the following:
• Up to a total of 200 records across all trees
• Up to five records of different types
• SObject trees up to five levels deep
• You can create 200 top level records, by only providing the top level
![Page 20: Building towards a Composite API Framework in Salesforce](https://reader031.vdocuments.site/reader031/viewer/2022030309/58f1a32c1a28abe4298b463f/html5/thumbnails/20.jpg)
TreeSave REST Resource (cont.)
• The Developer provides the record relations via a reference ID
• ReferenceId is used to link related records and to return errors
• Only Insert is supported
• Triggers, processes, and workflow rules fire separately for each of the
object levels
• EX – All triggers fire for all the top level records, then all fire for the second
level records, then third, etc…
• All records are rolled back on any error
• Error will indicate which referenceId had the error so that the developer
can take the appropriate action
![Page 21: Building towards a Composite API Framework in Salesforce](https://reader031.vdocuments.site/reader031/viewer/2022030309/58f1a32c1a28abe4298b463f/html5/thumbnails/21.jpg)
Example TreeSave Request
{"records" :[
{"attributes" : {"type" : "Account", "referenceId" : "ref1"},
"name" : "SampleAccount”, "phone" : "1234567890”, "website" :
"www.salesforce.com", "numberOfEmployees”: "100”, "type" : "Analyst”,
"industry" : "Banking",
"Contacts" : {
"records" : [
{"attributes" : {"type" : "Contact", "referenceId" : "ref2"},
"lastname" : "Smith”, "title" : "President”, "email" :
"[email protected]" },
{"attributes" : {"type" : "Contact", "referenceId" : "ref3"},
"lastname" : "Evans”, "title" : "Vice President”, "email" :
}},
{"attributes" : {"type" : "Account", "referenceId" : "ref4"},
"name”: "SampleAccount2”, "phone”: "1234567890”, "website" :
"www.salesforce2.com", "numberOfEmployees”: "100”, "type" : "Analyst”,
"industry" : "Banking”}]
}
![Page 22: Building towards a Composite API Framework in Salesforce](https://reader031.vdocuments.site/reader031/viewer/2022030309/58f1a32c1a28abe4298b463f/html5/thumbnails/22.jpg)
Example Successful TreeSave Response
{
"hasErrors" : false,
"results" : [ {
"referenceId" : "ref1",
"id" : "001B0000003xiAwIAI"
}, {
"referenceId" : "ref4",
"id" : "001B0000003xiAxIAI"
}, {
"referenceId" : "ref2",
"id" : "003B0000003l3L5IAI"
}, {
"referenceId" : "ref3",
"id" : "003B0000003l3L6IAI"
} ]
}
![Page 23: Building towards a Composite API Framework in Salesforce](https://reader031.vdocuments.site/reader031/viewer/2022030309/58f1a32c1a28abe4298b463f/html5/thumbnails/23.jpg)
Example Unsuccessful TreeSave Response
{
"hasErrors" : true,
"results" : [ {
"referenceId" : "ref4",
"errors" : [ {
"statusCode" : "REQUIRED_FIELD_MISSING",
"message" : "Required fields are missing: [Name]",
"fields" : [ "Name" ]
} ]
} ]
}
![Page 24: Building towards a Composite API Framework in Salesforce](https://reader031.vdocuments.site/reader031/viewer/2022030309/58f1a32c1a28abe4298b463f/html5/thumbnails/24.jpg)
TreeSave REST API Demo
![Page 25: Building towards a Composite API Framework in Salesforce](https://reader031.vdocuments.site/reader031/viewer/2022030309/58f1a32c1a28abe4298b463f/html5/thumbnails/25.jpg)
Building a Composite API on Salesforce
• There are a number of existing Composite resources
• The Batching REST resource allows for the sending of multiple REST
calls in a single round trip
• The calls are unrelated, simply reduces round trips
• The TreeSave REST resource allows creation of multiple records in a
single call
• Limited to insert and all-or-none saves
• Apex REST can be used to build custom logic
• Requires complete design by the developer
![Page 26: Building towards a Composite API Framework in Salesforce](https://reader031.vdocuments.site/reader031/viewer/2022030309/58f1a32c1a28abe4298b463f/html5/thumbnails/26.jpg)
Building a Composite API on Salesforce (cont.)
• A new API which will be a combination of Batch and TreeSave
• Outputs from one API call can be Inputs into another
• You can use the developer assigned Reference Id
• Ex - @Account1.id can be used in a later query, as a reference field, in an action, etc
• Friendly URLs will assist in navigating the resource hierarchy
• Ability to crawl the resource tree easily
• Ex - /services/data/v36.0/sobjects/Account/001X00000000123/Contacts will give you a list
of all Contacts on a the designated Account
• This will allow multiple CRUD operations to collections
• This will allow a simple layer of orchestration to the REST API
![Page 27: Building towards a Composite API Framework in Salesforce](https://reader031.vdocuments.site/reader031/viewer/2022030309/58f1a32c1a28abe4298b463f/html5/thumbnails/27.jpg)
Composite API Demo
![Page 28: Building towards a Composite API Framework in Salesforce](https://reader031.vdocuments.site/reader031/viewer/2022030309/58f1a32c1a28abe4298b463f/html5/thumbnails/28.jpg)
What did we Learn?
What is the Enterprise API
Existing Features that begin to support composite actions
• Batching API
• TreeSave API
• Composite API
Demos of existing resources
• Showed an example of Batching API
• Showed an example of TreeSave API
• Demo of potential Composite API
![Page 29: Building towards a Composite API Framework in Salesforce](https://reader031.vdocuments.site/reader031/viewer/2022030309/58f1a32c1a28abe4298b463f/html5/thumbnails/29.jpg)
Q&A
![Page 30: Building towards a Composite API Framework in Salesforce](https://reader031.vdocuments.site/reader031/viewer/2022030309/58f1a32c1a28abe4298b463f/html5/thumbnails/30.jpg)
Share Your Feedback, and Win a GoPro!
3Earn a GoPro prize entry for
each completed survey
Tap the bell to take a
survey2Enroll in a session1
![Page 31: Building towards a Composite API Framework in Salesforce](https://reader031.vdocuments.site/reader031/viewer/2022030309/58f1a32c1a28abe4298b463f/html5/thumbnails/31.jpg)
Thank you