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..

  • If your API endpoint supports CORS requests, you can use the standard XMLHttpRequest JavaScript object to make your AJAX callout. You will need to contact your provider to see if it is supported or not. – sfdcfox Sep 6 at 10:48

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.

  • $A.get('e.force:refreshView').fire(); is indirectly loading the page again. I am passing few parameters through URL. Based on that URL params, I am looping the same method until I get the response. so it is just reloading again and again.. Is there any other way to just render the updated fields?? I know that something can be done through AJAX, but I am not getting an IDEA.. – AshSFcloud Sep 6 at 10:20
  • I suggest you read up on refreshView and double check your current approach. By itself, it doesn't cause a page reload. – tsalb Sep 6 at 10:31
  • from the main Lightning Page, I am using three more other components(different sections of the page). so do I have to use '$A.get('e.force:refreshView').fire();' in the component which I have to refresh or on the main component? I am validating through small condition on 'init' in main lightning component. (I can not say parent child components as I am not using that method) – AshSFcloud Sep 10 at 5:23

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.