Introduction:
Refresh a Salesforce record page after a specific field change can enhance user experience and ensure data accuracy. This process involves using a record-triggered flow and an Aura component, leveraging platform event subscriptions to automatically update the record page in real-time. This guide will walk you through the steps to set up this functionality in Salesforce.
Components Involved
- List and describe the components involved in setting up the feature:
- Record-Triggered Flow
- Aura Component
- Platform Event
Step-by-Step Guide
- Creating the Aura Component
- In the Developer Console, go to File > New > Lightning Component.
- Enter a Name for your component (e.g., AccountRefreshComponent)
- Copy and paste the below code.
AccountRefreshComponent.cmp
<aura:component implements=“flexipage:availableForAllPageTypes” access=“global” >
<aura:handler name=“init” value=“{!this}” action=“{!c.doInit}” />
<lightning:empApi aura:id=“empApi” />
</aura:component>
AccountRefreshComponentController.js
({
doInit : function(component, event, helper) {
var channel = ‘/event/QuoteRefreshEvent__e’;
const replayId = -1;
const empApi = component.find(“empApi”);
//A callback function that’s invoked for every event received
const callback = function (message)
{
console.log(” ==== > Refreshed Sucessfully < === “);
$A.get(“e.force:refreshView”).fire();
var obj = message.data.payload;
};
// Subscribe to the channel and save the returned subscription object.
empApi.subscribe(channel, replayId, callback).then(function(newSubscription) {
//console.log(“Subscribed to channel 1” + channel);
});
const errorHandler = function (message) {
console.error(“Received error “, JSON.stringify(message));
};
//A callback function that’s called when an error response is received from the server for the handshake, connect, subscribe, and unsubscribe meta channels.
empApi.onError(errorHandler);
}
})
2.Subscribing to Platform Events
- Click on the Gear icon (Setup) in the upper-right corner.
- In the Quick Find box, type “Platform Events”.
- Select “Platform Events” from the search results.
- Click on the “New Platform Event” button.
- Create a platform event object as shown in the screenshot below
- Create a field called “Message” as shown in the screenshot below.
- Click Save button to apply the changes.
3.Setting Up the Record-Triggered Flow
- Use your Salesforce credentials to log in.
- Click on the Gear icon (Setup) in the upper-right corner.
- In the Quick Find box, type “Flows” and select Flows under Process Automation.
- Click on the New Flow button.
- In the Flow Type selector, choose Record-Triggered Flow.
- Click Create.
- Select the object you want to trigger the flow (e.g., Account).
- Configure the Create element as shown in the screenshot below.
(Note: Select the platform event you have created for the refresh.)
- Click the Save & Activate button to apply the changes.
Conclusion
In conclusion, the implementation of record-triggered flows and Aura components, coupled with platform event subscriptions, offers a seamless solution for dynamically refresh salesforce record page. By leveraging these functionalities, users can ensure real-time updates to specific fields, enhancing user experience and maintaining data accuracy. This integrated approach demonstrates Salesforce’s versatility in streamlining processes and facilitating efficient data management within organizations.