1

I am looking for an option to show the users always the latest data when a record is already been loaded but a backend process updates the records.

Scenario: If an Employee object record is opened by a user and while editing an Employee Code was manually entered on a standard edit page layout and saved, we programatically call an external system from future method which get's called from trigger to fetch additional details based on employee code and update the Employee record. As it's async transaction by the time record loads after editing and saved with employee code the data fetched from external system wont be available for users immediately.

Is there a way to show the latest changes to the user without them manually refreshing the screen.

1 Answer 1

0

Although it is limited on what you can with a standard record page, one option is to write a Visualforce page and embed it into the record page. What you need in the Visualforce page is an apex:actionPoller that polls the latest information of the record. Take Contact as an example:

Controller extension:

public with sharing class InlineController {
    private Id contactId;
    public Contact person {get;set;}
    
    public InlineController(ApexPages.StandardController controller) {    
        this.contactId = ApexPages.currentPage().getParameters().get('id');
        loadContact();
    }
    
    public PageReference poll() {
        loadContact();
        return null;
    }
    
    private void loadContact() {
        person = [select Id, FirstName, LastName from Contact where id = :contactId];
    }
}

Visualforce Page:

<apex:page standardController="contact" extensions="InlineController">
    <apex:form >
        <apex:pageBlock id="details">
            First Name: <apex:outputField value="{!person.FirstName}"/><br/>
            Last Name: <apex:outputField value="{!person.LastName}"/><br/>
        </apex:pageBlock>
        <apex:actionPoller action="{!poll}" reRender="details" interval="15"/>
    </apex:form>
</apex:page>

Then you should be able to drag and drop the Visualforce into the Contact layout like this. Once the record is updated at the backend, the embedded part is auto refreshed.

enter image description here

You also want to consider the performance by optimizing the polling.

Depending on how many fields are updated by the backend, you would consider if it makes sense to go with the option or create your own record page (Visualforce or Lightning).

1
  • Thanks Chun, this is a good workaround. I am exploring more to see if i can use Lightning Data Services as polling from the page may also to performance issues.
    – Rajasekhar
    Dec 15, 2020 at 12:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .