1// InterviewsController.apex2public class InterviewsController{3 @AuraEnabled(cacheable=true)4 public static String getPausedId(){5 // Get the ID of the running user.6 String currentUser = UserInfo.getUserId();7 // Find all of that user’s paused interviews for the Survey customers flow.8 List<FlowInterview>interviews =9[ SELECT Id FROM FlowInterview WHERE CreatedById = :currentUser AND10 InterviewLabel LIKE '%Survey customers%'];11 if(interviews == null || interviews.isEmpty()){12 return null; // early out13}14 // Return the ID for the first interview in the list.15 return interviews.get(0).Id;16}17}
Apex コントローラからインタビュー ID が返されると、pausedInterviewId が flow-interview-id 属性に渡されます。Apex コントローラから null のインタビュー ID が返されると、フロー名が flow-api-name 属性に渡されることにより、コンポーネントで新しいインタビューが開始されます。
1// myComponent.js2import{LightningElement, wire}from "lwc";3import getPausedId from "@salesforce/apex/InterviewsController.getPausedId";45export default class MyComponent extends LightningElement{6 flowName;7 pausedInterviewId;89 @wire(getPausedId)10 getPausedInterviewId({error, data}){11 if(error){12 // start a new interview since no interview id was returned.13 this.flowName = "Survey_customers";14}else if(data){15 // resume the flow with the returned interview id.16 this.pausedInterviewId = data;17}18}19}