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
Mario EMario E 

How to refresh the page after redirecting users at end of a Flow?

I created a VFP and Apex Controller that will run a Flow. In the flow, the Case ID will be passed through and take the user back to the same Case record after clicking a custom button.

The only issue here is that the page does not refresh to display the changes after the flow was executed.

// Redirects user to the same Case record after flow executes and reloads the page

public with sharing class custom_caseJiraFlowRedirectController {
    public Object custom_caseJiraFlowRedirectController() {
            String unique_id = ApexPages.currentPage().getParameters().get('id');
            if(unique_id == null){
               // Return Home if no ID 
               String url = '/home/home.jsp';
               return new PageReference(url); 
        } // Get Case ID and set Redirect
          String caseId = [SELECT Id,
                              caseFlowUniqueId__c
                              FROM Case
                              WHERE caseFlowUniqueId__c = :unique_id
                              ORDER BY CreatedDate
                              DESC LIMIT 1].Id;
           // Did we find a Case?
           if (caseId == null) {
           // Return Home if no ID
           String url = '/home/home.jsp';
           return new PageReference(url);
           }
           // Redirect to Case
           String url = '/' + caseId;
          return new PageReference(url); 
      }
  }

Do I need to add this line somewhere?
System.PageReference setRedirect(Boolean redirect)
Raghu NaniRaghu Nani
Hi Please create the new method which has return type of PageReference, instead of constructor move your code to that new method.
Please let me knoe if this works.
public PageReference newMethod() {
            //Your Code here
             PageReference tempPage = ApexPages.currentPage();
             tempPage.setRedirect(true);
             return tempPage;
}
Raghu NaniRaghu Nani
In above example, i mentioned the current page has reference, please change to your page(which you need to redirect)