2

I have a Visualforce page on a custom object that has a commandButton to update a field on the custom object. When that field is updated, a Process fires that then creates a case based on the information in the custom object record. All works fine. However, I would like to refresh the page once the Process fires. Is this possible?

CommandButton:

<apex:commandButton rendered="{!(CC.Create_Case__c == false)}" value="Create Case" action="{!CreateCase}" style="background:#d699ff; padding: 5px 10px 5px 10px"/>

Controller:

public with sharing class VF_Controller_CreateCampaignCase{

public Campaign_Create_Request__c CCR;

    public VF_Controller_CreateCampaignCase(ApexPages.StandardController myController){
        this.CCR = (Campaign_Create_Request__c)myController.getRecord();
    }

    public Void CreateCase() {
            CCR.Create_Case__c = true;
            update CCR;
    }
}
5

Thanks everyone. I got my problem resolved by changing the Void method in my controller to a PageReference method and then adding a redirect back to my current page. Thanks for all your help! Updated working code for my controller is below:

public with sharing class VF_Controller_CreateCampaignCase{

    public Campaign_Create_Request__c CCR;

    public VF_Controller_CreateCampaignCase(ApexPages.StandardController myController){
        this.CCR = (Campaign_Create_Request__c)myController.getRecord();
    }

    public PageReference CreateCase() {
        CCR.Create_Case__c = true;
        update CCR;

        PageReference tempPage = ApexPages.currentPage();            
        tempPage.setRedirect(true);
        return tempPage;
    }
}
2

If your commandbutton fires an action in your controller, you should just need to make that method return a PageReference, and then return null

Such as:

public pageReference updateFields() {
    // do some magic
    return null;
}

(and then the action on your commandbutton is something like:

<apex:commandButton action="{!updateFields}" value="Update!" />

)

Edit: That is, unless you already have all this in place and you only want to reload the page once your controller "knows" that the process has fired. Which might be more complicated.

  • 1
    for last one you should use action poller from page to ensure that some data has been updated -- developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/… – kurunve Jan 21 '16 at 16:33
  • That would be a very neat way to do that! – Simon Lawrence Jan 21 '16 at 16:43
  • @Simon - Yes, I already have the controller to update the field on my custom object. I updated my original post with it. I want to then refresh my VF page after the Process has completed. – J. Neilan Jan 21 '16 at 17:46
  • @kurunve - Thanks. I'll take a look at that, but does it continually refresh or can it just be a 1-tim refresh? – J. Neilan Jan 21 '16 at 17:50
1

You can do this using <apex:actionFunction> below is the code .

<apex:pageblocksection id="test">
<apex:actionfunction id="refresh" rerender="test"/>
<apex:commandButton reRender="test" />
</apex:pageblocksection>
  • Thanks. However, I want to refresh to occur automatically. I don't want the user to have to click a button to refresh. – J. Neilan Jan 21 '16 at 17:49
  • Add your current commandButton code to your question. – Ricky Jan 21 '16 at 17:59
  • Add reRender to your commnd button. reRender="YourBlockId". I will edit my answer accordingly. This should solve your problem – Ricky Jan 21 '16 at 18:42
  • Thanks. I added reRender to the CommandButton in my post above, but it still doesn't refresh the page after the Process completes. – J. Neilan Jan 21 '16 at 19:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.