function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MXGMXG 

Redirect page - user see old data

Hello community,
I'm new in salesforce development. I want to change the lead status & owner by clicking on a button.

I created a visualforce page and a class:
 
<apex:page standardController="Lead" extensions="LeadUpdater" action="{!UpdateLeadOwnerAndStatus}">
    <apex:form >
        <apex:inputHidden value="{!lead.OwnerId}" />
    </apex:form>
</apex:page>
public class LeadUpdater  {
	private Id ownerId;
	private Id leadId;
	private Lead lead;

	// constructor
	public LeadUpdater(ApexPages.StandardController controller) {
		this.lead = (Lead)controller.getRecord();
		this.leadId = lead.Id;
		System.debug('The lead to update is: ' + this.lead);
		this.ownerId = UserInfo.getUserId();
	}

	// update lead owner and status
	public PageReference UpdateLeadOwnerAndStatus() {
		// Logic
		this.lead.OwnerId = this.ownerId;
		this.lead.Status = 'XYZ';
		update this.lead;

		PageReference pageRef = new ApexPages.StandardController(this.lead).view();
		pageRef.setRedirect(true);

		return pageRef;
	}
}

Then I added the visualforce page to the "Salesforce1 and Lightning Experience Actions".

Now I can change status & owner by one click, BUT when the user redirect to the lead detail page - he see the old status&owner. The user has to reload the page 1-2 times to see the new data. Is there a way to reload the page with the new data via apex?