A sales process is normally completed by placing an order and contracting the products. In most cases, the actual ordering will be happening in an external system and not in salesforce. So in this case it is important to send order-related changes to the external system as soon as its status is updated in salesforce.

Salesforce has introduced a new standard platform event to support this- called OrderStatusChangedEvent. This is available as part of API version 51.0 and above.

Advertisement

Let us see this in detail:

How to enable OrderStatusChangedEvent

Under Order Setting, we can enable this standard platform event:

Setup->Feature Settings->Sales->Order Setting->Enable Order Events

When this will be fired?

This standard platform event will be fired when:

1. Status is updated for an existing order

Supported Subscribers

OrderStatusChangedEvent can be subscribed internally and externally.

Subscribing through Flows

Let us see an example of how to subscribe to standard OrderStatusChangedEvent using Flows.

Use Case – Notify Account Owner when an order status is updated 1. Create New Flow

Create a new flow of type platform event-Triggered flow:

2. Choose platform event

Choose platform event as “Order Status Changed event”

3. Assign recipient List

Our requirement is to send a notification to Account Owner when order status is updated. So let us create a list variable to store Account owner email.

And add an assignment Logic to populate this variable with Account owner’s email:

4. Send email Notification

Add an Action and select Send email.

Do the below assignment:

Body – Order status got updated to {!$Record.NewStatus} from {!$Record.OldStatus} Subject – {!$Record.Order.OrderNumber} – Status got updated

Email Addresses (collection) – variable – emaillist

Final Flow looks like below and you can activate it.

5. Update Order status to verify email

Let us create a new account, contract, order and add order product.

Then try to update Order status from Draft to Activated. The account owner will be receiving a new email notification.

Subscribing through Streaming API(CometD)

Please refer to this blogpost to understand how to subscribe to salesforce platform events using comentD.

Using the same approach we can see OrderStatusChangedEvent subscription details.

Use the below command to subscribe to OrderStatusChangedEvent .

java -classpath target/emp-connector-0.0.1-SNAPSHOT-phat.jar com.salesforce.emp.connector.example.LoginExample <username> <password+sectoken> /event/OrderStatusChangedEvent

Since platform events are available for 24 hours in the queue, you can see all the published events till this time getting subscribed:

Advantages of Consuming Standard platform Event

1. Internally – We will be able to keep related operations asynchronous and will be able to take advantages of govornor limits and performance.

2. Externally – Multiple systems will be able to subscribe to the standard event and no need to define custom process/approach for integration.

In our next blog, we can see another useful standard platform event.

Please click here to read the original article as posted on Meera-r-nair.

We source the web to bring you best Salesforce articles for our reader’s convenience. If you want to have this article removed, please follow guidelines at Digital Millennium Copyright Act (DMCA)..