Lightning コンポーネントからのフローインタビューの再開
デフォルトでは、ユーザは Salesforce Classic のホームページの [一時停止中のインタビュー] コンポーネントから一時停止中のインタビューを再開できます。ユーザがインタビューを再開できる方法と場所をカスタマイズするには、JavaScript コントローラでインタビュー ID を resumeFlow メソッドに渡します。
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})例
次の例では、インタビューを再開したり新しいインタビューを開始したりする方法を示します。ユーザが取引先責任者レコードから [Survey Customer (顧客調査)] をクリックすると、Lightning コンポーネントは次の 2 つのいずれかを実行します。
- [Survey Customers (顧客調査)] フローのインタビューが一時停止されている場合、最初のインタビューを再開する。
- [Survey Customers (顧客調査)] フローのインタビューが一時停止されていない場合、新しいインタビューを開始する。
1<aura:component controller="InterviewsController">
2 <aura:handler name="init" value="{!this}" action="{!c.init}" />
3 <lightning:flow aura:id="flowData" />
4</aura:component>この Apex コントローラは、SOQL クエリを実行して一時停止中のインタビューのリストを取得します。クエリから何も返されない場合、getPausedId() は null 値を返し、コンポーネント新しいインタビューが開始されます。クエリから 1 つ以上のインタビューが返されると、コンポーネントでそのリスト内の最初のインタビューが再開されます。
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}JavaScript コントローラが Apex コントローラからインタビュー ID を取得すると、コンポーネントでそのインタビューが再開されます。Apex コントローラから null のインタビュー ID が返されると、コンポーネントで新しいインタビューが開始されます。
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 Unique Name.
16 else {
17 flow.startFlow("Survey_customers");
18 }
19 });
20 //Send request to be enqueued
21 $A.enqueueAction(action);
22 },
23})