Item:
Refreshing a Lightning Aura component when a record is updated via the standard Salesforce UI
Share:
twitter social iconlinkedin social iconfacebook social icon
Image

Refreshing a Lightning Aura component when a record is updated via the standard Salesforce UI

By: Dan Nicholson

Lightning components offer a number of solutions to allow integration with Salesforce’s standard functionality, but one of the challenges people sometimes face is when a component needs to update, refresh or otherwise change as the result of a change to a standard object via the Salesforce UI. In the circumstances where no other triggering mechanisms are available, the option to ‘watch’ the Salesforce UI for changes would be useful. 

Lightning Data Service

In order to resolve this issue, we have one interesting approach using Lightning Data Service. Lightning Data Service (LDS) is a mechanism within the Lightning Experience that allows a custom Lightning component to retrieve data from Salesforce objects. 

The implementation of this is relatively simple, we add the code below to the markup and specify an attribute that the record data should be mapped to.

In addition to this, we can trigger actions on a change of this data, using the ‘recordUpdated’ attribute.

Shared Caching

Lightning Data Service and the standard Salesforce UI share an integrated cache, so that if one is updated the others also reflect that change. This means that if our custom component makes a change to the record in question, the standard UI does not continue to display stale date.

Similarly, we can leverage this functionality in the opposite direction to trigger a change within our component:

Markup

Appsolutely

JS Controller

recordUpdated : function(component, event, helper) {
 // Your custom functionality here
 alert(‘I have changed’);}

In this simple example we can allow a change to any fields within the given record to trigger custom functionality in our component, assuming the component is active at the time of the change.

We can also determine the type of change and handle each with different behaviours. For more information on change types, see developer.salesforce.com or contact us!

Have a look at more technical blogs ->


About the author

Dan Nicholson is a Lead Developer with 18 years of experience in Software Development. He has worked on AppExchange app development for over 7 years on over 20 apps. For two years, he also managed a team within Sage on one of the largest AppExchange apps available at the time with over 400 lightning components.

Want to know what Appsolutely can do for you?

Share this article:
twitter social iconfacebook social iconlinkedin social icon

divider graphic

Related

Secure third-party libraries in your managed package

Secure third-party libraries in your managed package

By: Hugo van Krimpen You are planning to release your very first application to the Salesforce AppEx...

Hugo van Krimpen
By Hugo van Krimpen
How to publish your SFDX plugin with these easy steps
April 6, 2021

How to publish your SFDX plugin with these easy steps

By: Guilherme Uhelski We all know that out-of-the-box commands that come with the Salesforce CLI onl...

Guilherme Uhelski
By Guilherme Uhelski
In the news: Capita's GrantIS live with the UK Department of International Trade
February 2, 2021

In the news: Capita's GrantIS live with the UK Department of International Trade

Appsolutely has the honour to work with Capita in the UK - a digital enabler of the grant management ...

Appsolutely
By Appsolutely