Newer Version Available

This content describes an older version of this product. View Latest

Resume a Flow Interview from an Aura Component

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.
1({
2    init : function (component) {
3        // Find the component whose aura:id is "flowData"
4        var flow = component.find("flowData");
5        
6        // In that component, resume a paused interview. Provide the method with
7        // the ID of the interview that you want to resume.
8        flow.resumeFlow("pausedInterviewId");
9     },
10})

Example

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.
1<aura:component controller="InterviewsController">
2    <aura:handler name="init" value="{!this}" action="{!c.init}" />
3    <lightning:flow aura:id="flowData" />
4</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.

1public class InterviewsController {
2   @AuraEnabled
3   public static String getPausedId() {
4      // Get the ID of the running user
5      String currentUser = UserInfo.getUserId();
6      // Find all of that user's paused interviews for the Survey customers flow
7      List<FlowInterview> interviews =
8         [ SELECT Id FROM FlowInterview
9           WHERE CreatedById = :currentUser AND InterviewLabel LIKE '%Survey customers%'];
10      
11      if (interviews == null || interviews.isEmpty()) {
12         return null; // early out
13      }
14      // Return the ID for the first interview in the list
15      return interviews.get(0).Id;
16   }
17}

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.

1({
2   init : function (component) {
3       //Create request for interview ID
4       var action = component.get("c.getPausedId");
5       action.setCallback(this, function(response) {
6          var interviewId = response.getReturnValue();
7          // Find the component whose aura:id is "flowData"
8          var flow = component.find("flowData");
9          // If an interview ID was returned, resume it in the component
10          // whose aura:id is "flowData".
11          if ( interviewId !== null ) { 
12             flow.resumeFlow(interviewID);
13          }
14          // Otherwise, start a new interview in that component. Reference
15          // the flow's API Name.
16          else {
17             flow.startFlow("Survey_customers");
18          }
19       });
20       //Send request to be enqueued
21       $A.enqueueAction(action);
22   },
23})