[SalesForce] show updated fields without reloading Lightning page

We are creating an INVOICE through Lightning form. Once the cx filled the form and press SAVE button, we are making a REST api call to java application and getting more details like invoice number, id etc and updating the invoice.

in order to save an invoice STANDALONE in salesforce, I am creating some random string values and assigning to invoice number, id and all (to whatever mandatory fields). As I am inserting random string right before callout, I am using @future method to take care of callout section.

As the callout(@future) runs asynchronously, we don't when will the response comes. So, right after pressing SAVE button, I am redirecting the page to another INVOICE lighting page with filled details in it which will have random ID,num etc for now. But, I want to update/show the fields once I got the response without reloading(I am updating the INVOICE with response body details right after callout finishes).

Please let me know if there is a way to reRender those values without reloading the page in LIGHTNING ASAP. (I am sorry that I can not provide you the code as there are multiple components for above mentioned application/configuration)

Thanks a ton.

In other words, refresh only one COMPONENT once I got the response instead of refreshing whole page or if there is a way to do that using AJAX in LIGHTNING please let me know…

Please note that I have already done with everything including callout. I am getting response and doing everything except the reRendering the updated fields without reloading the page. If I reload the page, there are no issues but Please suggest how to reRender the fields or a component without reloading the page..

Best Answer

Only way right now (v43) is to emit a platform event from a trigger/apex handler class or process builder action when the actual DML resolves. I'd probably include the sObject Id in the platform event payload here.

Once fired, you'll need a lightning component somewhere on your record flexipage to wrap a cometD implementation to listen to the platform event.

Then, you can unwrap the payload and check to see if it's the correct sObject Id and then use something like $A.get('e.force:refreshView').fire(); to get new values from database.

HOWEVER

If you wait until v44, it seems we are getting lightning:empApi which will reduce a lot of the overhead by manually rolling a cometD implementation.

Related Topic