How to refresh record details in Lightning when you change them in APEX

The Lightning is awesome and beauty, the problem I faced was simple – I created a Lightning Component, which called @Future method, which update some data in records. How can I update the screen after that, as it is all asynchronous?

The solution

After all, the solution is easy.

And the „all“ is the community, specificaly Andrew Fawcett in this case, who created this awesome component.

The second ingredient in this solution are the „still new“ platform events, which when I saw for the first time, I saved as something great for integration. But they are way bigger, they can replace triggers – as you can create and consume them in Flow and Process Builder – and they can pass messages around.

At the end the solution is really simple:

  • install Andrew’s component, tweak it if you want it to listen to just specific messages in events and fire the force:refreshView event,
  • drag it onto your Lightning page,
  • update your APEX code, so it creates the event.

Done and solved. It should be reliable as Platform Events are reliable, but who knows, from what I have seen it is a bit tricky.

You use Flow?

Maybe you use Flow to do your stuff. Luckily there is the „unofficial“ component for Flow, which does the same. In the Spring ’18 release it needs you to be part of the Local Flow Actions, from Summer ’18 it should be generally available. And it requires you to use the Screen flow 🙁 so no process builder starting the flow.

Leave a Reply