Access to external data depends on the connections between Salesforce and the external systems that store the data. Network latency and the availability of the external systems can introduce timing issues with Apex write or delete operations on external objects.
Because of the complexity of these connections, Apex can’t execute standard insert(), update(), or create() operations on external objects. Instead, Apex provides a specialized set of database methods and keywords to work around potential issues with write execution. DML insert, update, create, and delete operations on external objects are either asynchronous or executed when specific criteria are met.
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); } }
You can perform the following DML operations on external objects, either asynchronously or based on criteria: insert records, update records, upsert records, or delete records. Use classes in the DataSource namespace to get the unique identifiers for asynchronous jobs, or to retrieve results lists for upsert, delete, or save operations.
When you initiate an Apex method on an external object, a job is scheduled and placed in the background jobs queue. The BackgroundOperations sObject lets you view job status for write operations via the API or SOQL. Monitor job progress and related errors in the org, extract statistics, process batch jobs, or see how many errors occur in a specified time period.
For usage information and examples, see Database Namespace and DataSource Namespace.