By default, users can resume interviews that they paused from the Paused Interviews component on their home page. To customize how and where users can resume their interviews, embed the lightning:flow component in a custom Aura component. In your client-side controller, pass the interview ID into the resumeFlow method.
({
init: function (component) {
// Find the component whose aura:id is "flowData"
var flow = component.find("flowData");
// In that component, resume a paused interview. Provide the method with
// the ID of the interview that you want to resume.
flow.resumeFlow("PAUSED_INTERVIEW_ID");
},
});
This example shows how you can resume an interview—or start a new one. When users click Survey Customer from a contact record, the Aura component does one of two things.
- If the user has any paused interviews for the Survey Customers flow, it resumes the first one.
- If the user doesn’t have any paused interviews for the Survey Customers flow, it starts a new one.
<aura:component controller="InterviewsController">
<aura:handler name="init" value="{!this}" action="{!c.init}" />
<lightning:flow aura:id="flowData" />
</aura:component>
This Apex controller gets a list of paused interviews by performing a SOQL query. If nothing is returned from the query, getPausedId() returns a null value, and the component starts a new interview. If at least one interview is returned from the query, the component resumes the first interview in that list.
public class InterviewsController {
@AuraEnabled
public static String getPausedId() {
// Get the ID of the running user
String currentUser = UserInfo.getUserId();
// Find all of that user's paused interviews for the Survey customers flow
List<FlowInterview> interviews =
[ SELECT Id FROM FlowInterview
WHERE CreatedById = :currentUser AND InterviewLabel LIKE '%Survey customers%'];
if (interviews == null || interviews.isEmpty()) {
return null; // early out
}
// Return the ID for the first interview in the list
return interviews.get(0).Id;
}
}
If the Apex controller returned an interview ID, the client-side controller resumes that interview. If the Apex controller returned a null interview ID, the component starts a new interview.
({
init: function (component) {
//Create request for interview ID
var action = component.get("c.getPausedId");
action.setCallback(this, function (response) {
var interviewId = response.getReturnValue();
// Find the component whose aura:id is "flowData"
var flow = component.find("flowData");
// If an interview ID was returned, resume it in the component
// whose aura:id is "flowData".
if (interviewId !== null) {
flow.resumeFlow(interviewID);
}
// Otherwise, start a new interview in that component. Reference
// the flow's API Name.
else {
flow.startFlow("Survey_customers");
}
});
//Send request to be enqueued
$A.enqueueAction(action);
},
});
See Also