[[{“value”:”
In this post, we will explore how to use the Salesforce PubSub adapter in SAP Cloud Integration (SAP CI) to subscribe to Platform Events in Salesforce. This approach enables real-time, event-driven communication between Salesforce and external systems without the need for frequent polling or API calls.
What is the Salesforce PubSub Adapter (Sender)?
The Salesforce Pub/Sub Sender Adapter uses the Pub/Sub API, built on the gRPC protocol. It allows SAP CI to listen to Salesforce event streams in real time. Instead of polling for changes or using REST API calls, this adapter maintains a persistent connection to Salesforce’s event bus, capturing events as they occur.
What are Platform Events?
Platform Events in Salesforce provide an event-driven mechanism to exchange data inside and outside Salesforce in real time. Instead of continuously querying Salesforce for changes, external systems like SAP CI can subscribe to Platform Events and react immediately when specific business conditions occur. This results in faster, cleaner, and more scalable integrations.
The true power of Platform Events lies in their ability to capture only the relevant business signals. Unlike Change Data Capture, which publishes every record change, Platform Events allow you to include only required fields, apply qualification rules, and fire events only when specific business conditions are met. This ensures cleaner, lighter, and more meaningful integrations — especially in event-driven scenarios where SAP CI needs to react only to critical events rather than process noise.
Creating a Platform Event in Salesforce
Let’s create a sample Platform Event for the Account object. This event will send qualified Account data.
- Navigate to Setup → Quick Find → Platform Events → New Platform Event.
- Fill in the details:
• Singular Label: AccountPlatformEvent
• Plural Label: Accounts
• API Name: AccountPlatformEvent__e
• Description: Event to send qualified Accounts to External system.
• Leave default retention (72 hours). - Create required custom fields (example):
• AccountId__c – Text(18)
• Name__c – Text(255)
• Industry__c – Text(50)
• Rating__c – Text(50)
These fields define the schema of your event messages.
Publishing Platform Events Using Apex
Next, we will publish the Platform Event whenever an Account record is created or updated. Below is a sample Apex trigger that publishes an event message, it can be created from Developer console of the Salesforce.
trigger AccountPlatformEventPublisher on Account (after insert, after update) {
List<AccountPlatformEvent__e> events = new List<AccountPlatformEvent__e>();
for (Account acc : Trigger.new) {
events.add(new AccountPlatformEvent__e(
AccountId__c = acc.Id,
AccountSource__c = acc.AccountSource,
AnnualRevenue__c = acc.AnnualRevenue,
BillingCity__c = acc.BillingCity,
BillingCountry__c = acc.BillingCountry,
BillingStreet__c = acc.BillingStreet,
CreatedDate__c = acc.CreatedDate,
CurrencyIsoCode__c = acc.CurrencyIsoCode,
Industry__c = acc.Industry,
IsDeleted__c = String.valueOf(acc.IsDeleted),
LastModifiedDate__c = acc.LastModifiedDate,
Name__c = acc.Name,
Rating__c = acc.Rating,
SAPCustomerNumber__c= acc.SAPCustomerNumber__c
));
}
if (!events.isEmpty()) {
Database.SaveResult[] results = EventBus.publish(events);
System.debug(‘Published ‘ + results.size() + ‘ Account events.’);
}
}
Subscribing to Platform Events Using the PubSub Adapter
Once the Platform Event is created, configure the Salesforce Pub/Sub Sender adapter in SAP CI to subscribe to the event channel. Below are key features and configuration parameters:
- Subscribe to Salesforce channels to receive events.
- Supports publishing of events to channels with defined schemas.
- Retrieve schemas using the ‘Get Schema’ operation.
- Support for OAuth 2.0 Username-Password and OAuth 2.0 JWT Bearer authentication.
- Replay options to control event retrieval (Earliest, Latest, Custom).
- Error handling and re-subscription mechanisms.
Below is the detailed description of each parameter used in this iflow covering Salesforce PubSub adapter.
We are using sender Salesforce PubSub adapter to consume the platform events, configurations are as below.
SAP CI Iflow:
Sender : Pick a sender from the pallet and select the Salesforce Pub Sub Adapter from the adapter list
Configuration of Salesforce Pub Sub Sender Adapter:
Parameter Description:
|
Host |
Specify the host to which the proxy requests are sent for the gRPC API (towards the gRPC host). The proxy requests to the gRPC host will go through the proxy. Example: api.pubsub.salesforce.com |
|
Port |
Specify the port to which the proxy requests are sent for the gRPC API (towards the gRPC port). The proxy requests to the gRPC port will go through the proxy. Example: 7443 |
|
Tenant ID |
Specify the Salesforce Organization ID, this can be found in Company Information within the “Setup” page on Salesforce |
|
Authentication |
Select the authentication type to be used for the connection to Salesforce:
|
| ℹ️ | The following fields are available when OAuth 2.0 JWT Bearer is selected. |
|
Token URL |
Specify the login endpoint to your Salesforce instance url. Example: https://login.salesforce.com for Salesforce production environment, https://test.salesforce.com for Salesforce Sandbox environment and https://{MyDomain}.my.salesforce.com in case MyDomain is enabled on the org. |
|
Credential Name |
Specify the User Credentials storing the username-password details. |
|
Security Token Alias |
Specify the Security Token Alias that refers to the secure parameter. This can be omitted if your SAP CI IP address has been whitelisted in Salesforce |
|
OAuth Credential Name |
Specify the User Credentials that stores the Consumer key-Client secret pair. |
| ℹ️ | The following fields are available when OAuth 2.0 JWT Bearer is selected. |
|
Audience |
Specify the login endpoint to your Salesforce instance URL. Example: https://login.salesforce.com for Salesforce production environment, https://test.salesforce.com for Salesforce Sandbox environment, and https://site.force.com/customers if implementing for an Experience Cloud site |
|
Subject Alias |
Specify the Secure Parmeter that stores the username of the Salesforce user. |
|
Issuer Alias |
Specify the Secure Parameter which indicates the OAuth client_id of the connected app in Salesforce for which the certificate was registered. |
|
Keystore Alias |
Specify the alias name of the added JKS file in Keystore as a Key Pair. It consists of a key and certificate to sign the JWT |
|
Expiration (in ms) |
Specifies the validity of the assertion in milliseconds |
Processing Tab:
| Channel Name | Specify the Salesforce channel name to perform the subscription. (here we will use the /event/ and then the API name of the Platform event created in previous steps in Salesfoce.) |
| Replay ID Approach |
Select the replay option in the first FetchRequest:
|
|
Replay ID |
Specify the Replay ID value. The Replay ID is populated by Salesforce and refers to the position of the event in the event stream. Example: 8381402 |
|
Request Batch Size |
Specify the number of events to be requested in the Salesforce fetchRequest. The default value is 100 |
|
Replay Preset for Invalid Replay ID |
Select the replay option in case “sfdc.platform.eventbus.grpc.subscription.fetch.replayid.corrupted” error occurs:
|
|
Duplicate Check Expiration (in ms) |
Specify the expiry time in milliseconds while handling the Duplicate check. The default value is 300000 |
|
Process Errors as an Event |
Enable this property to write error events in the exchange. If disabled, issues connecting to event streams will only be written to the logs |
Deployment of the IFlow:
Now lets deploy the IFlow and see how this works, For demostration, I will create the Account record and then update it.
Demo:
New account created in Salesforce:
As soon the record is saved in the Salesforce, the event/message is generated which is received by SAP CI
{
“payload”: {
“AccountId__c”: “001J100000X6REOIA3”,
“AnnualRevenue__c”: 10000,
“CurrencyIsoCode__c”: “USD”,
“Name__c”: “Test Account For Demo”,
“BillingCountry__c”: “India”,
“Industry__c”: “Finance”,
“AccountSource__c”: null,
“CreatedDate__c”: 1760449971000,
“CreatedById”: “0055g00000AqVaAAAV”,
“SAPCustomerNumber__c”: “101”,
“CreatedDate”: 1760449971276,
“BillingStreet__c”: “ABC Road”,
“LastModifiedDate__c”: 1760449971000,
“Rating__c”: “Warm”,
“IsDeleted__c”: “false”,
“BillingCity__c”: “Pune”
},
“schemaId”: “3lrXZmbw8vDsOdsDj74Qpw”,
“id”: “644d0292-d8b7-4fd4-9c5d-5f64eefb7bca”
}
Now lets update the Account and see the event, I will update the name and the City
New event received in SAP CI
In order to see the replay Id of the event we need to check the headers after the Salesforce PubSub adapter step:
Replay Id when Account was created:
Replay Id of the update event:
Observations
- Only the fields defined in the Platform Event schema are included in the payload.
- Each update triggers the transmission of the complete message again.
Conclusion
Using Salesforce Platform Events with the SAP CI PubSub adapter enables truly event-driven integrations between Salesforce and external systems. By defining only the necessary fields and publishing them through an Apex trigger, you ensure that downstream systems receive lean, relevant data instead of full records. The Pub/Sub adapter maintains a persistent gRPC connection for real-time delivery, minimizing API usage and latency. This approach provides a scalable, reliable, and modern integration pattern for enterprise-grade Salesforce-to-SAP scenarios.
Thanks,
Manish Deshpande
“}]]
Read More Technology Blog Posts by Members articles
#abap