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
Robert Webber 6Robert Webber 6 

Refresh not working for commandbutton

I have not been able to refresh a pageblocksection from a commandbutton. My VF is below. I thought I would just refresh the entire page from the commandbutton action "Investment Workflow" with the code following the VF. It doesn't do anything, either. What am I doing wrong? Appreciate any help.

Visualforce:
            <apex:pageBlockSection columns="3" id="idWorkflow" collapsible="False">
                <apex:outputText label="Current State" value="{!Development_Investment__c.WorkflowState__c}" style="font-size:15px"/>
                <apex:pageBlockSectionItem>
                    <apex:commandButton value="{!WorkflowLabel}" style="width:175px;" action="{!InvestmentWorkflow}" rerender="idWorkflow,idMessages"/>            
                    <apex:selectList value="{!SelectedWorkflowState}" size="1" style="width:150px" disabled="{!if(Development_Investment__c.WorkflowApprovalState__c='Submitted','True','False')}" >
                        <apex:selectOptions value="{!WorkflowStateOptions}"/>                        
                    </apex:selectList>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>

InvestmentWorkflow return code:

        String url = '/'+investmentID;
        PageReference page = new PageReference(url);
        page.setRedirect(True);
        return page;



 
Best Answer chosen by Robert Webber 6
Robert Webber 6Robert Webber 6
Thanks for responding, but this didn't solve the problem. It was a dumb mistake on my part. I was using

value="{!Development_Investment__c.WorkflowState__c}"

in the text box assuming it was going to change. Of course, it doesn't change unless I use a getter. Working code is below.

The lesson here is that if your fields are not really changing, then the refresh will do nothing. Check that first.

VisualForce:

            <apex:pageBlockSection columns="3" id="idWorkflow" collapsible="False">
                <apex:outputText label="Current State" value="{!WorkflowState}" style="font-size:15px"/>
                <apex:pageBlockSectionItem>
                    <apex:commandButton value="{!WorkflowLabel}" style="width:175px;" action="{!InvestmentWorkflow}" rerender="idWorkflow,idWorkflowMessages"/>            
                    <apex:selectList value="{!SelectedWorkflowState}" size="1" style="width:150px" disabled="{!if(WorkflowApprovalState ='Submitted','True','False')}" >
                        <apex:selectOptions value="{!WorkflowStateOptions}"/>                        
                    </apex:selectList>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>

New Getter:

    public String getWorkflowState() {
        Development_Investment__c inv = [Select State__c From Development_Investment__c Where ID=:investmentID];
        return inv.State__c;
    }





 

All Answers

ANUTEJANUTEJ (Salesforce Developers) 
Hi Robert,

>> https://salesforce.stackexchange.com/questions/159084/refresh-vf-page/159092

In the above implementation there is a way can you try checking if it works??

>> https://salesforce.stackexchange.com/questions/106252/reload-visualforce-page-after-update

This shows an implementation of the automatic refresh, you can try checking.

Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.  

Thanks.
Robert Webber 6Robert Webber 6
Thanks for responding, but this didn't solve the problem. It was a dumb mistake on my part. I was using

value="{!Development_Investment__c.WorkflowState__c}"

in the text box assuming it was going to change. Of course, it doesn't change unless I use a getter. Working code is below.

The lesson here is that if your fields are not really changing, then the refresh will do nothing. Check that first.

VisualForce:

            <apex:pageBlockSection columns="3" id="idWorkflow" collapsible="False">
                <apex:outputText label="Current State" value="{!WorkflowState}" style="font-size:15px"/>
                <apex:pageBlockSectionItem>
                    <apex:commandButton value="{!WorkflowLabel}" style="width:175px;" action="{!InvestmentWorkflow}" rerender="idWorkflow,idWorkflowMessages"/>            
                    <apex:selectList value="{!SelectedWorkflowState}" size="1" style="width:150px" disabled="{!if(WorkflowApprovalState ='Submitted','True','False')}" >
                        <apex:selectOptions value="{!WorkflowStateOptions}"/>                        
                    </apex:selectList>
                </apex:pageBlockSectionItem>
            </apex:pageBlockSection>

New Getter:

    public String getWorkflowState() {
        Development_Investment__c inv = [Select State__c From Development_Investment__c Where ID=:investmentID];
        return inv.State__c;
    }





 
This was selected as the best answer