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?
Is there any way how to display the changes?
Out of the box - No.
There are couple of ways you can do so though.
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.
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
isValidfield 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.