# legacydeveloper Integration Patterns And Practices - Full Documentation # Batch Data Synchronization ## Context You’re moving your CRM implementation to Salesforce and want to: - Extract and transform accounts, contacts, and opportunities from the current CRM system and load the data into Salesforce (initial data import). - Extract, transform, and load customer billing data into Salesforce from a remote system on a weekly basis (ongoing). - Extract customer activity information from Salesforce and import it into an on-premises data warehouse on a weekly basis (ongoing). ## Problem How do you import data into Salesforce and export data out of Salesforce, taking into consideration that these imports and exports can interfere with end-user operations during business hours, and involve large amounts of data? ## Forces There are various forces to consider when applying solutions based on this pattern: - Should the data be stored in Salesforce? If not, there are other integration options an architect can and should consider (mashups, for example). - If the data should be stored in Salesforce, should the data be refreshed in response to an event in the remote system? - Should the data be refreshed on a scheduled basis? - Does the data support primary business processes? - Are there analytics (reporting) requirements that are impacted by the availability of this data in Salesforce? ## Solution The following table contains various solutions to this integration problem.
| Solution | Fit | Data master | Comments |
|---|---|---|---|
| Salesforce Change Data Capture | Best | Salesforce | Salesforce Change Data Capture publishes change events, which represent changes to
Salesforce records. Changes include creation of a new record, updates to an existing
record, deletion of a record, and undeletion of a record. With Change Data Capture, you can receive near-real-time changes of Salesforce records, and synchronize corresponding records in an external data store. Change Data Capture takes care of the continuous synchronization part of replication. It publishes the deltas of Salesforce data for new and changed records. Change Data Capture requires an integration app for receiving events and performing updates in the external system. |
| Replication via third-party ETL tool | Best | Remote system | Leverage a third-party ETL tool that allows you to run change data capture against
source data. The tool reacts to changes in the source data set, transforms the data, and then calls Salesforce Bulk API to issue DML statements. This can also be implemented using the Salesforce SOAP API. |
| Replication via third-party ETL tool | Good | Salesforce | Leverage a third-party ETL tool that allows you to run change data capture against
ERP and Salesforce data sets. In this solution, Salesforce is the data source, and you can use time/status information on individual rows to query the data and filter the target result set. This can be implemented by using SOQL together with SOAP API and the query() method, or by using SOAP API and the getUpdated() method. |
| Remote call-in | Suboptimal | Remote system | It’s possible for a remote system to call into Salesforce by using one of the
APIs and perform updates to data as they occur. However, this causes considerable on-going
traffic between the two systems. Greater emphasis should be placed on error handling and locking. This pattern has the potential for causing continual updates, which has the potential to impact performance for end users. |
| Remote process invocation | Suboptimal | Salesforce | It’s possible for Salesforce to call into a remote system and perform updates
to data as they occur. However, this causes considerable on-going traffic between the two
systems. Greater emphasis should be placed on error handling and locking. This pattern has the potential for causing continual updates, which has the potential to impact performance for end users. |
| Error location | Error handling and recovery strategy |
|---|---|
| Read from Salesforce using Change Data Capture |
|
| Read from Salesforce using a 3rd party ETL system |
If the operation succeeds but there are failed records, an immediate restart or subsequent execution of the job should address the issue. In this case, a delayed restart might be a better solution because it allows time to triage and correct data that might be causing the errors. |
| Write to Salesforce |
If the operation succeeds but there are failed records, an immediate restart or subsequent execution of the job should address the issue. In this case, a delayed restart might be a better solution because it allows time to triage and correct data that might be causing the errors. |
| External master system | Errors should be handled in accordance with the best practices of the master system. |
| Solution | Fit | Comments |
|---|---|---|
| Salesforce Connect | Best | Use Salesforce Connect to access data from external sources, along with your
Salesforce data. Pull data from legacy systems such as SAP, Microsoft, and Oracle in real
time without making a copy of the data in Salesforce. Salesforce Connect maps data tables in external systems to external objects in your org. External objects are similar to custom objects, except that they map to data located outside your Salesforce org. Salesforce Connect uses a live connection to external data to always keep external objects up-to-date. Accessing an external object fetches the data from the external system in real time. Salesforce Connect lets you:
To access data stored on an external system using Salesforce Connect, you can use one of the following adapters:
|
| Request and Reply | Suboptimal | Use Salesforce web service APIs to make ad-hoc data requests to access and update
external system data. This solution includes the following approaches: Use Salesforce SOAP API. A custom Visualforce page or button initiates an Apex SOAP callout in a synchronous manner. In Salesforce, you can consume a WSDL and generate a resulting proxy Apex class. This class provides the necessary logic to call the remote service. A user-initiated action on a Visualforce page then calls an Apex controller action that executes this proxy Apex class to perform the remote call. Visualforce pages require customization of the Salesforce app. Use Salesforce REST API. A custom Visualforce page or button initiates an Apex HTTP callout (REST service) in a synchronous manner. In Salesforce, you can invoke HTTP services using standard GET, POST, PUT, and DELETE methods. You can use several HTTP classes to integrate with RESTful services. A user-initiated action on a Visualforce page then calls an Apex controller action that executes these proxy Apex classes to perform the remote call. Visualforce pages require customization of the Salesforce app. For more information on this solution, see Remote Process Invocation—Request and Reply. |
| Solution | Endpoint Considerations |
|---|---|
| Salesforce Connect |
OData APIs—Uses the Open Data Protocol to access data that’s stored outside Salesforce. The external data must be exposed via OData producers. Other APIs—Use the Apex Connector Framework to develop your own custom adapter when the other available adapters aren’t suitable for your needs. A custom adapter can obtain data from any source. For example, some data can be retrieved from the internet via callouts, while other data can be manipulated or even generated programmatically. Connect to Salesforce—Uses the Lightning Platform REST API to access data that’s stored in other Salesforce orgs. Connect via Middleware Connect via Middleware—The Salesforce Connect partner ecosystem has worked closely with Salesforce to make sure that their middleware gateways expose OData endpoints from their service so Salesforce can connect with them without writing additional code. |
| Request & Reply |
Apex SOAP Callouts
The endpoint must be able to receive a web service call via HTTP. Salesforce must be able to access the endpoint over the public Internet. Apex HTTP Callouts The endpoint must be able to receive HTTP calls. Salesforce must be able to access the endpoint over the public Internet. You can use Apex HTTP callouts to call RESTful services using the standard GET, POST, PUT, and DELETE methods. |
| Term | Definition |
|---|---|
| Event handling | Event handling is the receipt of an identifiable occurrence at a designated receiver
(“handler”). The key processes involved in event handling include:
Keep in mind that the event handler can ultimately forward the event to an event consumer. Common uses of this feature with middleware can be extended to include the popular “publish/subscribe” or “pub/sub” capability. In a publish/subscribe scenario, the middleware routes requests or messages to active data-event subscribers from active data-event publishers. These consumers with active listeners can then retrieve the events as they’re published. In Salesforce integrations using middleware, the middleware layer assumes control of event handling. It collects all relevant events, synchronous or asynchronous, and manages distribution to all endpoints, including Salesforce. Alternatively, this capability can be achieved with the Salesforce enterprise messaging platform by using the event bus with platform events. See http://searchsoa.techtarget.com/definition/event-handler. |
| Protocol conversion | Protocol conversion “is typically a software application that converts the
standard or proprietary protocol of one device to the protocol suitable for another device
to achieve interoperability. In the context of middleware, connectivity to a particular target system may be constrained by protocol. In such cases, the message format needs to be converted to or encapsulated within the format of the target system, where the payload can be extracted. This is also known as tunneling. ” 1 Salesforce doesn’t support native protocol conversion, so it’s assumed that any such requirements are met by the middleware layer or the endpoint. See https://www.techopedia.com/definition/30653/protocol-conversion. |
| Translation and transformation | Transformation is the ability to map one data format to another to ensure
interoperability between the various systems being integrated. Typically, the process
entails reformatting messages en route to match the requirements of the sender or recipient.
In more complex cases, one application can send a message in its own native format, and two
or more other applications can each receive a copy of the message in their own native
format. Middleware translation and transformation tools often include the ability to create service facades for legacy or other non-standard endpoints. These service facades allows those endpoints to appear to be service-addressable. With Salesforce integrations, it’s assumed that any such requirements are met by the middleware layer or the endpoint. Transformation of data can be coded in Apex, but we don’t recommend it due to maintenance and performance considerations. See http://en.wikipedia.org/wiki/Message-oriented_middleware. |
| Queuing and buffering | Queuing and buffering generally rely on asynchronous message passing, as opposed to a
request-response architecture. In asynchronous systems, message queues provide temporary
storage when the destination program is busy or connectivity is compromised. In addition,
most asynchronous middleware systems provide persistent storage to back up the message
queue. The key benefit of an asynchronous message process is that if the receiver application fails for any reason, the senders can continue unaffected. The sent messages simply accumulate in the message queue for later processing when the receiver restarts. Salesforce provides only explicit queuing capability in the form of workflow-based outbound messaging. To provide true message queueing for other integration scenarios, including orchestration, process choreography, and quality of service, a middleware solution is required. See http://en.wikipedia.org/wiki/Message-oriented_middleware. |
| Synchronous transport protocols | Synchronous transport protocols refer to protocols that support activities wherein a “single thread in the caller sends the request message, blocks to wait for the reply message, and then processes the reply....The request thread awaiting the response implies that there is only one outstanding request or that the reply channel for this request is private for this thread.”2 |
| Asynchronous transport protocols | Asynchronous transport protocols refer to protocols supporting activities wherein “one thread in the caller sends the request message and sets up a callback for the reply. A separate thread listens for reply messages. When a reply message arrives, the reply thread invokes the appropriate callback, which reestablishes the caller’s context and processes the reply. This approach enables multiple outstanding requests to share a single reply thread.”3 |
| Mediation routing | Mediation routing is the specification of a complex “flow” of messages
from component to component. For example, many middleware-based solutions depend on a
message queue system. While some implementations permit routing logic to be provided by the
messaging layer itself, others depend on client applications to provide routing information
or allow for a mix of both paradigms. In such complex cases, mediation on the part of
middleware simplifies development, integration, and validation. “Specifically, Mediators coordinate a group of objects so that they [do not] need to know how to coordinate with each other….Then, each consumer could focus on processing a particular kind of message, and the coordinator [Mediator] could make sure that the right message gets to the right consumer.”4 |
| Process choreography and service orchestration | Process choreography and service orchestration are each forms of “service
composition” where any number of endpoints and capabilities are being
coordinated. The difference between choreography and service orchestration is:
In addition, “an orchestration shows the complete behavior of each service whereas the choreography combines the interface behavior descriptions of each service.”7 Portions of business process choreographies can be built in Salesforce workflows or using Apex. We recommend that all complex orchestrations be implemented in the middleware layer because of Salesforce timeout values and governor limits, especially in solutions requiring true transaction handling. |
| Transactionality (encryption, signing, reliable delivery, transaction management) | Transactionality can be defined as the ability to support global transactions that
encompass all necessary operations against each required resource. Transactionality implies
the support of all four ACID properties, atomicity, consistency, isolation, durabilit, where
atomicity guarantees all-or-nothing outcomes for the unit of work (transaction). While Salesforce is transactional within itself, it’s not able to participate in distributed transactions or transactions initiated outside of Salesforce. Therefore, it’s assumed that for solutions requiring complex, multi-system transactions, transactionality and associated roll-back/compensation mechanisms are implemented at the middleware layer. |
| Routing | Routing can be defined as specifying the complex flow of messages from component to
component. In modern services-based solutions, such message flows can be based on a number
of criteria, including header, content type, rule, and priority. With Salesforce integrations, it’s assumed that any such requirements are met by the middleware layer or the endpoint. Message routing can be coded in Apex, but we don’t recommend it due to maintenance and performance considerations. |
| Extract, transform, and load | Extract, transform, and load (ETL) refers to a process that involves:
While not strictly necessary, most mature ETL tools provide a change data capture capability. This capability is where the tool identifies records in the source system that have changed since the last extract, which reduces the amount of record processing. Salesforce now also supports Change Data Capture, which is the publishing of change events that represent changes to Salesforce records. With Change Data Capture, the client or external system receives near-real-time changes of Salesforce records. With this information, the client or external system can synchronize corresponding records in an external data store. See http://en.wikipedia.org/wiki/Extract,_transform,_load and Change Data Capture Developer Guide. |
| Long polling | Long polling, also called Comet programming, emulates an information push from a
server to a client. Similar to a normal poll, the client connects and requests information
from the server. However, instead of sending an empty response if information isn’t
available, the server holds the request and waits until information is available (an event
occurs). The server then sends a complete response to the client. The client then
immediately re-requests information. The client continually maintains a connection to the
server, so it’s always waiting to receive a response. If the server times out, the client
connects again and starts over. The Salesforce Streaming API uses the Bayeux protocol and
CometD for long polling.
|
| Aspect | Description |
|---|---|
| Type | Specifies the style of integration: Process, Data, or Virtual.
|
| Timing | Specifies the blocking (or non-blocking) nature of the integration.
|
| Solution | Fit | Comments |
|---|---|---|
| SOAP API | Best |
|
| REST API | Best |
|
| Apex web services | Suboptimal | Apex class methods can be exposed as web service methods to external applications.
This method is an alternative to SOAP API, and is typically used only where the following
additional requirements must be met.
The benefit of using an Apex web service must be weighed against the additional code that needs to be maintained in Salesforce. Not applicable for platform events because transaction pre-insert logic at the consumer doesn’t apply in an event-driven architecture. To notify a Salesforce org that an event has occurred, use SOAP API, REST API, or Bulk API 2.0. |
| Apex REST services | Suboptimal | An Apex class can be exposed as REST resources mapped to specific URIs with an HTTP
verb defined against it (for example, POST or GET). You can use REST API composite resources to perform multiple updates in a single transaction. Unlike SOAP, there’s no need for the client to consume a service definition/contract (WSDL) and generate client stubs. The remote system requires only the ability to form an HTTP request and process the returned results (XML or JSON). Not applicable for platform events because transaction pre-insert logic at the consumer doesn’t apply in an event-driven architecture. To notify a Salesforce org that an event has occurred, use SOAP API, REST API, or Bulk API 2.0. |
| Bulk API 2.0 | Optimal for bulk operations | Bulk API 2.0 is based on REST principles, and is optimized for loading or deleting
large sets of data. It has the same accessibility and security behavior as REST API. Any data operation that includes more than 2,000 records is a good candidate for Bulk API 2.0 to successfully prepare, execute, and manage an asynchronous workflow that uses the Bulk framework. Jobs with fewer than 2,000 records should involve “bulkified” synchronous calls in REST (for example, Composite) or SOAP. Bulk API 2.0 allows the client application to query, insert, update, upsert, or delete a large number of records asynchronously by submitting a number of batches, which are processed in the background by Salesforce. In contrast, SOAP API is optimized for real-time client applications that update small numbers of records at a time. Although SOAP API can also be used for processing large numbers of records, when the data sets contain hundreds of thousands to millions of records, it becomes less practical. This is due to its relatively high overhead and lower performance characteristics.
|
| Calling mechanism | Description |
|---|---|
| SOAP API | The remote system uses the Salesforce Enterprise or Partner WSDL to generate client stubs that are in turn used to invoke the standard SOAP API. |
| REST API | The remote system has to authenticate before accessing any Apex REST service. The
remote system can use OAuth 2.0 or username and password authentication. In either case,
the client must set the authorization HTTP header with the appropriate value (an OAuth
access token or a session ID can be acquired via a login call to SOAP API). The remote system then generates REST invocations (HTTP requests) with the appropriate verbs and processes the results returned (JSON and XML data formats are supported). |
| Apex web service | The remote system consumes the custom Apex web service WSDL to generate client stubs that are in turn used to invoke the custom Apex web service. |
| Apex REST service | As per REST API, the resource URI and applicable verbs are defined using the @RestResource, @HttpGet, and @HttpPost annotations. |
| Bulk API 2.0 | Bulk API 2.0 is a REST-based API, so the same calling mechanisms as REST API apply. |
| REST API to invoke Flow | Use REST API to call a custom invocable actions endpoint to invoke an auto-launched flow. |
| Solution | Security considerations |
|---|---|
| SOAP API | Salesforce supports Secure Sockets Layer v3 (SSL) and the Transport Layer Security
(TLS) protocols. Ciphers must have a key length of at least 128 bits. The remote system must log in using valid credentials to obtain a session ID. If the remote system already has a valid session ID, then it can call the API without an explicit login. This is used in call-back patterns covered earlier in this document, where a preceding Salesforce outbound message contained a session ID and record ID for subsequent use. We recommend that clients that call SOAP API cache and reuse the session ID to maximize performance, rather than obtaining a new session ID for each call. |
| REST API | We recommend that the remote system establish an OAuth trust for authorization. REST
calls can then be made on specific resources using HTTP verbs. It’s also possible to make
REST calls with a valid session ID that might have been obtained by other means (for
example, retrieved by calling SOAP API or provided via an outbound message). We recommend that clients that call the REST API cache and reuse the session ID to maximize performance, rather than obtaining a new session ID for each call. |
| Apex web service | We recommend that the remote system establish an OAuth trust for authorization. |
| Apex REST service | We recommend that the remote system establish an OAuth trust for authorization. |
| Bulk API 2.0 | We recommend that the remote system establish an OAuth trust for authorization. |
| Solution | Communication type | Limits |
|---|---|---|
| SOAP API or REST API | Synchronous |
|
| Bulk API 2.0 | Synchronous |
Bulk API 2.0 is optimized for importing and exporting large sets of data asynchronously. Any data operation that includes more than 2,000 records is a good candidate for Bulk API 2.0 to successfully prepare, execute, and manage an asynchronous workflow that uses the Bulk framework. Jobs with fewer than 2,000 records should involve “bulkified” synchronous calls in REST (for example, Composite) or SOAP. Bulk API 2.0 is synchronous when submitting the batch request and associated data. The actual processing of the data occurs asynchronously. For more information about API and batch processing limits, see Limits. |
| Solution | Endpoint considerations |
|---|---|
| SOAP API | The remote system must be capable of implementing a client that can call the
Salesforce SOAP API, based on a message format predefined by Salesforce. The remote system (client) must participate in a contract-first implementation where the contract is supplied by Salesforce (for example, Enterprise or Partner WSDL). |
| REST API | The remote system must be capable of implementing a REST client that invokes Salesforce—defined REST services, and processes the XML or JSON results. |
| Apex web service | The remote system must be capable of implementing a client that can invoke SOAP
messages of a predefined format, as defined by Salesforce. The remote system must participate in a code-first implementation, where the contract is supplied by Salesforce after the Apex web service is implemented. Each Apex web service has its own WSDL. |
| Apex REST service | The same endpoint considerations as REST API apply. |
| Solution | Limits |
|---|---|
| SOAP API, REST API, and custom Apex APIs |
|
| Bulk API 2.0 | See Data Volumes sidebar for more information. |
| Platform Events |
|
| Solution | Fit | Comments |
|---|---|---|
| Process-driven platform events | Best | No customization is required in Salesforce to implement platform events. The
recommended solution is when the remote process is invoked from an insert or update
event. Platform events are event messages (or notifications) that your apps send and receive to take further action. Platform events simplify the process of communicating changes and responding to them without writing complex logic. One or more subscribers can listen to the same event and carry out actions. For example, a software system can send events containing information about printer ink cartridges. Subscribers can subscribe to the events to monitor printer ink levels and place orders to replace cartridges with low ink levels. External apps can listen to event messages by subscribing to a channel through CometD. Platform apps, such as Visualforce pages and Lightning components, can subscribe to event messages with CometD as well. |
| Customization-driven platform events | Good | Similar to process-driven platform events, but the events are created by Apex
triggers or classes. You can publish and consume platform events by using Apex or an
API. Platform events integrate with the Salesforce platform through Apex triggers. Triggers are the event consumers on the Salesforce platform that listen to event messages. When an external app uses the API or a native Salesforce app uses Apex to publish the event message, a trigger on that event is fired. Triggers run the actions in response to the event notifications. |
| Workflow-driven outbound messaging | Good | No customization is required in Salesforce to implement outbound messaging. The
recommended solution for this type of integration is when the remote process is invoked
from an insert or update event. Salesforce provides a workflow-driven outbound messaging
capability that allows sending SOAP messages to remote systems triggered by an insert or
update operation in Salesforce. These messages are sent asynchronously and are independent
of the Salesforce user interface. The outbound message is sent to a specific remote endpoint. The remote service must be able to participate in a contract-first integration where Salesforce provides the contract. On receipt of the message, if the remote service doesn’t respond with a positive acknowledgment, Salesforce retries sending the message, providing a form of guaranteed delivery. When using middleware, this solution becomes a “first-mile” guarantee of delivery. |
| Outbound messaging and callbacks | Good | Callbacks provide a way to mitigate the impacts of out-of-sequence messaging. In
addition, they handle these scenarios.
The outbound message provides a unique SessionId that you can use as an authentication token to authenticate and authorize a callback with either the SOAP API or the REST API. The system performing the callback isn’t required to separately authenticate to Salesforce. The standard methods of either API can then be used to perform the desired business functions. A typical use of this variant is the scenario in which Salesforce sends an outbound message to a remote system to create a record. The callback updates the original Salesforce record with the unique key of the record created in the remote system. |
| Custom Lightning component or Visualforce page that initiates an Apex SOAP or HTTP asynchronous callout | Suboptimal | This solution is typically used in user interface-based scenarios, but does require
customization. In addition, the solution must handle guaranteed delivery of the message in
the code. Similar to the solution for the Remote Process Invocation—Request and Reply pattern solution that specifies using a Visualforce page or Lightning component, together with an Apex callout. The difference is that in this pattern, Salesforce doesn’t wait for the request to complete before handing off control to the user. After receiving the message, the remote system responds and indicates receipt of the message, then asynchronously processes the message. The remote system hands control back to Salesforce before it begins to process the message; therefore, Salesforce doesn’t have to wait for processing to complete. |
| Trigger that’s invoked from Salesforce data changes performs an Apex SOAP or HTTP asynchronous callout | Suboptimal | You can use Apex triggers to perform automation based on record data changes. An Apex proxy class can be executed as the result of a DML operation by using an Apex trigger. However, all calls made from within the trigger context must be executed asynchronously. |
| Batch Apex job that performs an Apex SOAP or HTTP asynchronous callout | Suboptimal | Calls to a remote system can be performed from a batch job. This solution allows for batch remote process execution and for processing of the response from the remote system in Salesforce. However, there are limits to the number of calls for a given batch context. For more information, see the Salesforce Developer Limits and Allocations Quick Reference. |
| Solution | Error Handling and Recovery Strategy |
|---|---|
| Apex callouts |
|
| Outbound messaging |
|
| Platform Events |
|
| Solution | Security Considerations |
|---|---|
| Apex callouts | A call to a remote system must maintain the confidentiality, integrity, and
availability of the request. The following are security considerations specific to using
Apex SOAP and HTTP calls in this pattern.
|
| Outbound Messaging | For outbound messaging, one-way SSL is enabled by default. However, two-way SSL can
be used together with the Salesforce outbound messaging certificate. The following are some additional security considerations.
|
| Platform Events | For platform events the subscribing external system must be able to authenticate to
the Salesforce Streaming API. Platform events conform to the existing security model configured in the Salesforce org. To subscribe to an event, the user needs read access to the event entity. To publish an event, the user needs create permission on the event entity. |
| Solution | Endpoint Considerations |
|---|---|
| Apex SOAP callouts | The endpoint must be able to process a web service call via HTTP. Salesforce must be
able to access the endpoint over the public Internet. This solution requires that the
remote system is compatible with the standards supported by Salesforce. At the time of
writing, the web service standards supported by Salesforce for Apex SOAP callouts are:
|
| Apex HTTP callouts | The endpoint must be able to receive HTTP calls and be accessible over the public
internet by Salesforce. Apex HTTP callouts can be used to call RESTful services using the standard GET, POST, PUT, and DELETE methods. |
| Outbound message |
|
| Platform Events |
|
| Master System | Description |
|---|---|
| Salesforce | The remote system must store either the Salesforce RecordId or some other unique surrogate key in the Salesforce record. |
| Remote system | Salesforce must store a reference to the unique identifier in the remote system.
Because the process is asynchronous, storing this unique identifier can’t be part of
the original transaction. Salesforce must provide a unique ID in the call to the remote process. The remote system must then call back to Salesforce to update the record in Salesforce with the remote system’s unique identifier, using the Salesforce unique ID. The callback implies specific state handling in the remote application to store the Salesforce unique identifier for that transaction to use for the callback when processing is complete, or the Salesforce unique identifier is stored on the remote system’s record. |
| Solution | Considerations |
|---|---|
| Apex callouts | In certain cases, solutions prescribed by this pattern require implementing several
complex integration scenarios best served using middleware or having Salesforce call a
composite service. These scenarios include:
|
| Outbound messaging | Given the static, declarative nature of the outbound message, no complex integration scenarios, such as aggregation, orchestration, or transformation, can be performed in Salesforce. The remote system or middleware must handle these types of operations . |
| Platform Events | Given the static, declarative nature of events, no complex integration scenarios, such as aggregation, orchestration, or transformation can be performed in Salesforce. The remote system or middleware must handle these types of operations . |
| Solution | Reliable Messaging Considerations |
|---|---|
| Apex callouts | Salesforce doesn’t provide explicit support for reliable messaging protocols
(for example, WS-ReliableMessaging). We recommend that the remote endpoint receiving the
Salesforce message implement a reliable messaging system, like JMS or MQ. This system
ensures full end-to-end guaranteed delivery to the remote system that ultimately processes
the message. However, this system doesn’t ensure guaranteed delivery from Salesforce
to the remote endpoint that it calls. Guaranteed delivery must be handled through customizations to Salesforce. Specific techniques, such as processing a positive acknowledgment from the remote endpoint in addition to custom retry logic, must be implemented. |
| Outbound messaging | Outbound messaging provides a form of reliable messaging. If no positive
acknowledgment is received from the remote system, the process retries for up to 24 hours.
This process guarantees delivery only to the point of the remote listener. The retry
interval increases exponentially over time, starting with 15-second intervals and ending
with 60-minute intervals. The overall retry period can be extended to seven days by request
to Salesforce support, but automatic retries are limited to 24 hours. All failed messages
after 24 hours are placed in a queue and administrators must monitor this queue for any
messages exceeding the 24-hour delivery period and retry manually, if necessary. In most implementations, the remote listener calls another remote service. Ideally, the invocation of this remote service through a reliable messaging system ensures full end-to-end guaranteed delivery. The positive acknowledgment to the Salesforce outbound message occurs after the remote listener has successfully placed its own message on its local queue. Once the positive acknowledgment is received by Salesforce, automatic retries are stopped. |
| Platform Events | Platform Events attempts to provide reliable messaging by temporarily persisting
event messages in the event bus. Subscribers can catch up on missed event messages by
replaying messages from the event bus using the Replay ID of event messages. The event bus is a distributed system and doesn’t have the same guarantees as a transactional database. As a result, Salesforce can’t provide a synchronous response for an event publish request. Events are queued and buffered, and Salesforce attempts to publish the events asynchronously. In rare cases, the event message might not be persisted in the distributed system during the initial or subsequent attempts. This means that the events aren’t delivered to subscribers, and they aren’t recoverable. |
| Solution | Fit | Comments |
|---|---|---|
| Enhanced External Services invokes a REST API call | Best | Enhanced External Services allows you to invoke an externally hosted service in a
declarative manner (no code required). This feature is best used when the following
conditions are met:
|
|
Salesforce Lightning—Lightning component or page initiates a synchronous Apex SOAP or REST callout. Salesforce Classic—A custom Visualforce page or button initiates a synchronous Apex SOAP callout. If the remote endpoint poses a risk of high latency response (refer to latest limits documentation for the applicable limits here), then an asynchronous callout, also called a continuation, is recommended to avoid hitting synchronous Apex transaction governor limits. |
Best | Salesforce enables you to consume a WSDL and generate a resulting proxy Apex class.
This class provides the necessary logic to call the remote service. Salesforce also enables you to invoke HTTP (REST) services using standard GET, POST, PUT, and DELETE methods. A user-initiated action on a Visualforce page or Lightning page then calls an Apex controller action that then executes this proxy Apex class to perform the remote call. Visualforce pages and Lightning pages require customization of the Salesforce application. |
| A custom Visualforce page or button initiates a synchronous Apex HTTP callout. | Best |
Salesforce enables you to invoke HTTP services using standard GET, POST, PUT, and DELETE methods. You can use several HTTP classes to integrate with RESTful services. It’s also possible to integrate to SOAP-based services by manually constructing the SOAP message. The latter isn’t recommended because it’s possible for Salesforce to consume WSDLs to generate proxy classes. A user-initiated action on a Visualforce page then calls an Apex controller action that then executes this proxy Apex class to perform the remote call. Visualforce pages require customization of the Salesforce application. |
| A synchronous trigger that’s invoked from Salesforce data changes performs an asynchronous Apex SOAP or HTTP callout. | Suboptimal | You can use Apex triggers to perform automation based on record data changes. An Apex proxy class can be executed as the result of a DML operation by using an Apex trigger. However, all calls made from within the trigger context must execute asynchronously from the initiating event. Therefore, this solution isn’t recommended for this integration problem. This solution is better suited for the Remote Process Invocation—Fire and Forget pattern. |
| A batch Apex job performs a synchronous Apex SOAP or HTTP callout. | Suboptimal | You can make calls to a remote system from a batch job. This solution allows batch
remote process execution and processing of the response from the remote system in
Salesforce. However, a given batch has limits to the number of calls. For more information,
see Governor Limits. A given batch run can execute multiple transaction contexts (usually in intervals of 200 records). The governor limits are reset per transaction context. |
| Calling Mechanism | Description |
|---|---|
|
Enhanced External service embedded in a flow or Lightning component or Visualforce and Apex controllers |
Used when the remote process is triggered as part of an end-to-end process involving the user interface, and the result must be displayed or updated in a Salesforce record. For example, the submission of a credit card payment to an external payment gateway and the payment results are immediately returned and displayed to the user. |
| Apex triggers | Used primarily for invocation of remote processes using Apex callouts from DML-initiated events. For more information about this calling mechanism, see pattern Remote Process Invocation—Fire and Forget. |
| Apex batch classes | Used for invocation of remote processes in batch. For more information about this calling mechanism, see pattern Remote Process Invocation—Fire and Forget. |
| Solution | Endpoint Considerations |
|---|---|
| Apex SOAP callouts |
The endpoint must be able to receive a web service call via HTTP. Salesforce must be able to access the endpoint over the public Internet. This solution requires that the remote system is compatible with the standards supported
by Salesforce. At the time of
writing, the web service standards supported by Salesforce for Apex SOAP callouts
are:
|
| Apex HTTP callouts | The endpoint must be able to receive HTTP calls. Salesforce must be able to access the
endpoint over the public Internet. You can use Apex HTTP callouts to call REST services using the standard GET, POST, PUT, and DELETE methods. |