Two-Way Integration with Writable External Objects

24
Two-Way Integration with Writable External Objects Alexey Syomichev Architect [email protected] @syomichev

Transcript of Two-Way Integration with Writable External Objects

Page 1: Two-Way Integration with Writable External Objects

Two-Way Integration with Writable External Objects

 Alexey Syomichev  Architect  [email protected]  @syomichev  

Page 2: Two-Way Integration with Writable External Objects

 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.

Safe Harbor

Page 3: Two-Way Integration with Writable External Objects

 Extract-Transform-Load (ETL) approach to data integration does not always work:

§  Has to be driven by an ETL system;

§  Synchronized dataset goes stale immediately;

  External Objects allow data integration without physically moving the data:

§  Back-office data is always up to date;

§  Now includes write access!

External Objects  Data Federation on Salesforce Platform

Page 4: Two-Way Integration with Writable External Objects

1.  Example of integration architecture

2.  External Data Source configuration

3.  Editing external objects

4.  Writing to external objects via API

5.  Writing to external object in Apex

6.  Questions

Session outline

Page 5: Two-Way Integration with Writable External Objects

Use case Example architecture

Page 6: Two-Way Integration with Writable External Objects

 Throughout this session we will be exploring an example integration consisting of:

§  Account data maintained in Salesforce;

§  Order data maintained in back-office system;

§  Relationship is by a business key

Data Integration Example

Page 7: Two-Way Integration with Writable External Objects

Setup Data Source configuration parameters

Page 8: Two-Way Integration with Writable External Objects

 Enable external writes using a new checkbox in data source parameters.

 To be configured as writable, an OData service must support additional HTTP verbs:

§  POST

§  PUT

§  MERGE/PATCH

§  DELETE

Configuration

Page 9: Two-Way Integration with Writable External Objects

Create, Edit, Delete Making changes in external data via UI

Page 10: Two-Way Integration with Writable External Objects

§  Standard UI for Edit, Create, Delete

§  Remote save is requested immediately

§  Any remote failure manifests as a user-visible error

Editing external objects

Page 11: Two-Way Integration with Writable External Objects

§  Create, Edit and Delete also supported in mobile UI

Mobile editing

Page 12: Two-Way Integration with Writable External Objects

API Saving or deleting external data via sObject API

Page 13: Two-Way Integration with Writable External Objects

§  Workbench

§  SOAP API

§  REST API

Multi-object save has to be homogeneous:

§  Transaction boundaries

§  “AllOrNothing” semantics

External writes with API

Page 14: Two-Way Integration with Writable External Objects

Apex Building complex data modification scenarios

Page 15: Two-Way Integration with Writable External Objects

 Apex allows to build logic that involves multiple related data modifications.

§  Local changes are added to the transaction and are committed together at the end of Apex context.

§  Remote changes are not tied to the transaction, and cannot be requested immediately while there is a local transaction open.

 Account acct = new Account(name = “SAP”);  insert acct;

 Opportunity oppt = new Opportunity(account = acct);  insert oppt;

 SalesOrder__x order = new SalesOrder__x();  order.account = acct;  insert order;

Complex scenarios

Page 16: Two-Way Integration with Writable External Objects

No distributed transactions or two-phase commit:

§  Salesforce core database has ACID properties: §  Atomic §  Consistent §  Isolated §  Durable

§  External writes follow BASE semantics: §  Basically available §  Soft state §  Eventually consistent

Transactional Semantics

Page 17: Two-Way Integration with Writable External Objects

In class System.Database there are new operations exclusively for external objects:

-  For insert, update and delete;

-  Of “immediate” and “async” behavior;

-  Async operations come with or without callback option

External CRUD operations

 Database.insertImmediate(obj);    Database.insertAsync(obj);    Database.insertAsync(obj,  cb);  

 Database.updateImmediate(obj);    Database.updateAsync(obj);    Database.updateAsync(obj,  cb);  

 Database.deleteImmediate(obj);    Database.deleteAsync(obj);    Database.deleteAsync(obj,  cb);  

Page 18: Two-Way Integration with Writable External Objects

Database.insertAsync()

 public void createOrder() {   SalesOrder__x order = new SalesOrder__x();   Database.SaveResult sr = Database.insertAsync(order);   if (!sr.isSuccess()) {   String locator = Database.getAsyncLocator(sr);   completeOrderCreation(locator);   }  }

 @future  public void completeOrderCreation(String locator) {   SaveResult sr = Database.getAsyncResult(locator);   if (sr.isSuccess()) {   System.debug(“sales order has been created”);   }  }

Page 19: Two-Way Integration with Writable External Objects

Asynchronous callback

 global class SaveCallback extends DataSource.AsyncSaveCallback {   override global void processSave(Database.SaveResult sr) {   if (sr.isSuccess()) {   System.debug("Save complete: Id = " + st.getId());   }   }  }

public void createOrder() {

  SalesOrder__x order = new SalesOrder__x();   SaveCallback callback = new SaveCallback();   Database.updateAsync(order, callback);  }

Page 20: Two-Way Integration with Writable External Objects

 Asynchronous external writes follow the eventual consistency model with BASE semantics, as opposed to ACID semantics of Salesforce core DB:

§  Reads performed shortly after writes may not reflect the changes

§  Writes will eventually reach the remote system

§  Even when Salesforce is the only writing system, remote data may change over time without current input: as queued up changes flow out, repeated reads may return different results

§  There is no ordering guarantees between writes issued from unrelated contexts

§  Conflict resolution strategy is up to the remote system, but in most naive configuration the latest change to be applied wins

§  Coordinated changes can be orchestrated with compensating transactions

Consistency Model – Design Considerations

Page 21: Two-Way Integration with Writable External Objects

 Asynchronous writes can be tracked by org admin in the BackgroundOperation sObject:

Monitoring

SELECT Id, Status, CreatedDate, StartedAt, FinishedAt, RetryCount, Error FROM BackgroundOperation WHERE Name = 'SalesOrder__x upsert' ORDER BY CreatedDate DESC

Page 22: Two-Way Integration with Writable External Objects

§  External writes are synchronous when performed via API or UI

§  API save cannot mix external and regular objects

§  Apex code can perform external writes only via Database.insertAsync() et al.

§  Database.insertAsync() is separate to avoid confusion with transactional insert()

§  Asynchronous writes offer eventual consistency model

§  Apex code cannot use insert()/update()/create() on external objects

§  Apex code can supply callbacks for compensating actions

§  Admin can monitor background write via API/SOQL

§  Available in Winter’16

Summary

Page 23: Two-Way Integration with Writable External Objects

Share Your Feedback, and Win a GoPro!

3 Earn a GoPro prize entry for each completed survey

Tap the bell to take a survey 2Enroll in a session 1

Page 24: Two-Way Integration with Writable External Objects

Thank you