OrderStatusChangedEvent - Salesforce Standard Platform Event fired during Order Status Changes
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.
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"
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.
Email:
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.
This comment has been removed by the author.
ReplyDeleteMeera Hi,
ReplyDeleteThank you for your post!
Can you elaborate further on the differences between using this event with Platform Event-Trigger Flow rather than, for example, using an after trigger Flow?
After trigger flow is synchronous execution - meaning, that operation is part of your current process, in our case order update. So this can affect, governor limits and save performance. But when you fire a platform event and then we use platform event based operations to do additional operations - it is getting executed in a separate thread. meaning asynchronously. For operations which consumes more time/governor limits - always asynchronous mode of execution is better.
DeleteGot it, thank you very much for your answer!
DeleteNice and good article. It is very useful for me to learn and understand easily
ReplyDeleteSalesforce CPQ Online Training Hyderabad
Salesforce CPQ Online Training India