I have trigger on contact which validates phone by calling external API. To be able to call the the API from trigger, I'm using future annotation. The callout method writes the result to custom field on the contact object (let's say it's checkbox 'isValid'). The problem is, when user edit and save the record, the isValid field value is not properly displayed on the frontend and I have to refresh the page... (It's lightning page, not VF). I know it's because the future callout. Is there any way how to display the changes? The only way is probably to create custom lightning component for the phone, right?

  • As of now No, but its in pipeline. youtube.com/watch?v=uSJChzSNGm4&feature=youtu.be&t=2341 – Pranay Jaiswal Nov 19 '18 at 18:55
  • 1
    to expand on Jayant's answer, if your trigger is doing callouts (hence future), the LEX component apex controller should not use future as response won't be synchronous. Create a service layer class abstraction that both trigger and non-trigger can use, and do future only when you're in a trigger context – cropredy Nov 20 '18 at 22:41

Is there any way how to display the changes?

Out of the box - No.

There are couple of ways you can do so though.

  1. This is the recommended approach. You should create a custom lightning component using force:editRecord. Then you can make the validation callout from your component apex controller, and refresh the component once you get success/failure response using force:refreshView. This way you will have the request/response and updates based on response be processed synchronously and see the updates in real time.

  2. Not recommended. If you still want to keep your current approach, you can create a poller component, which keeps on reading the value of the isValid field from the record and still utilize force:refreshView to refresh the overall screen to be able to reflect the updated status. However, because this is still asynchronous call, if at all the User navigates away from the screen before the component can refresh the view, this will not serve any purpose.

    If at all you want to utilize this approach, you will need to create a component and have that on the Lightning Page of your record. To be able to create a poller component, you can utilize the approach as mentioned in the documentation for Modifying Components Outside the Framework Lifecycle.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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