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
mbondmbond 

commandButton to refresh current page

I currently have a button that will call out to an external server and retrieve a value.  That value is then placed in a field for the same record.  Everything works right now.  The problem is that instead of refreshing the current tab/page, it opens a new window and the user needs to press Back to see the current data.  If they close the new window, then they see the old data.  How can I get the button to refresh the current tab/page after updating the value?

 

Thanks,

Matt

Best Answer chosen by Admin (Salesforce Developers) 
mbondmbond

The action was returning null already.  However, I found the solution.  There is a setting that needs to be changed.

 

Edit the object that was being refreshed (mine was in App Setup>Create>Objects).

Go to the Custom Button and Link section.

Edit the button that called the problem VisualForce page.

Change the Behavior to any one of the 3 options that start with "Display in existing window...".

Save the Custom Button/Link.

 

Thanks for helping!

Matt

All Answers

Damien_Damien_

it would be useful it you showed how you do it currently, but in order to just refresh the page you should

return null;

 

from you controller on the button click.

mbondmbond

Here's my code, minus the parts that do the retrieval.  You can see that the GetUnitsAvailableOnPage method does return null.  

 

Thanks,
Matt

 

VisualForce Page:

<apex:page standardController=
"Zuora__SubscriptionProductCharge__c" extensions="SubscriptProdChrgsAction" action="{!GetUnitsAvailableOnPage}"> 
<apex:form > 
<apex:pageBlock title="Refresh Remaining Units from TitleSphere Account"> 
<apex:messages /> 
<apex:pageBlockButtons > 
<apex:commandButton value="Back" action="{!back}"/> 
</apex:pageBlockButtons> 
</apex:pageBlock> 
<apex:outputText value="{!Zuora__SubscriptionProductCharge__c.Id}" rendered="false"/> 
</apex:form>
<apex:page>

 

 

Extension/Apex class:

public without sharing class SubscriptProdChrgsAction {
	private ApexPages.standardController controller;
	private Zuora__SubscriptionProductCharge__c subProdChrg;
	private Account acct;
	public SubscriptProdChrgsAction (ApexPages.standardController controller) {
		this.controller = controller;
		//set private fields' values...
	}
	public PageReference GetUnitsAvailableOnPage() {
		//retrieve value from external server...
		//update field in object...
		update subProdChrg;
		ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO,'Units Available successfully Retrieved.'));
		return null;
	}
	public PageReference back() {
		return controller.view();
	}
}
Damien_Damien_

I think what your problem might be, is that it looks like you are trying to use that function to help initialize the page.  You need to be setting everything up in the constructor instead.

<apex:page standardController=
"Zuora__SubscriptionProductCharge__c" extensions="SubscriptProdChrgsAction" action="{!GetUnitsAvailableOnPage}">

If you look at the action of the ApexPages, the last line says that it should not be used for initialization.  I believe this is your problem.

 

 
actionApexPages.ActionThe action method invoked when this page is requested by the server. Use expression language to reference an action method. For example, action="{!doAction}" references the doAction() method in the controller. If an action is not specified, the page loads as usual. If the action method returns null, the page simply refreshes. This method will be called before the page is rendered and allows you to optionally redirect the user to another page. This action should not be used for initialization.
mbondmbond

The action was returning null already.  However, I found the solution.  There is a setting that needs to be changed.

 

Edit the object that was being refreshed (mine was in App Setup>Create>Objects).

Go to the Custom Button and Link section.

Edit the button that called the problem VisualForce page.

Change the Behavior to any one of the 3 options that start with "Display in existing window...".

Save the Custom Button/Link.

 

Thanks for helping!

Matt

This was selected as the best answer