Customize How Users Resume Paused Flow Interviews
- If the user does, it resumes the first one.
- If the user doesn’t, it starts a new one.
Create the Visualforce and Apex Controller
Because the Visualforce page will be referenced in a contact-specific button, it must use that standard controller. Use a controller extension to add more logic to the page with Apex, which is where the page gets the ID of the interview to resume.
1<apex:page
2 standardController="Contact" extensions="MyControllerExtension_SurveyCustomers">
3 <flow:interview name="Survey_Customers" pausedInterviewId="{!pausedId}"/>
4</apex:page>This Apex controller extension performs a SOQL query to get a list of paused interviews. If nothing is returned from the query, getPausedId() returns a null value, and the Visualforce page starts a new interview. If at least one interview is returned from the query, the Visualforce page resumes the first interview in that list.
1public class MyControllerExtension_SurveyCustomers {
2
3 // Empty constructor, to allow use as a controller extension
4 public MyControllerExtension_SurveyCustomers(
5 ApexPages.StandardController stdController) { }
6
7 // Flow support methods
8 public String getInterviews() { return null; }
9
10 public String showList { get; set; }
11
12 public String getPausedId() {
13 String currentUser = UserInfo.getUserId();
14 List<FlowInterview> interviews =
15 [SELECT Id FROM FlowInterview WHERE CreatedById = :currentUser AND InterviewLabel LIKE '%Survey Customers%'];
16
17 if (interviews == null || interviews.isEmpty()) {
18 return null; // early out
19 }
20
21 // Return the ID for the first interview in the list
22 return interviews.get(0).Id;
23 }
24}Reference the Visualforce Page from a Page Layout
To actually expose this Visualforce page to your users, make it available from the Contact page layout.
| Field | Value |
|---|---|
| Label | Survey Customer |
| Display Type | Detail Page Button |
| Content Source | Visualforce Page |
| Content | YourVisualforcePage |
Finally, add the button to your Contact page layout.