この文章は Salesforce 機械翻訳システムを使用して翻訳されました。詳細はこちらをご参照ください。
英語に切り替える

Lightning コンポーネントからのフロー変数値の設定

Lightning コンポーネントにフローを埋め込んだら、その変数、sObject 変数、コレクション変数、sObject コレクション変数を初期化して、フローにより多くのコンテキストを提供します。コンポーネントのコントローラで、対応付けのリストを作成し、そのリストを startFlow メソッドに渡します。

変数を設定できるのはインタビューの開始時のみで、設定した変数で入力アクセスが許可されている必要があります。それぞれのフロー変数では、入力アクセスは次の項目によって制御されます。

  • Cloud Flow Designer の [入力/出力種別] 変数項目
  • Metadata API の FlowVariableisInput 項目

入力アクセスを許可しない変数を参照している場合、その変数を設定しようとしても無視されます。

メモ

設定した各変数の nametypevalue を指定します。type には、フローデータ型を使用します。

フロー変数の型 有効な値
テキスト String 文字列値または同等の式
数値 Number 数値または同等の式
通貨 Currency 数値または同等の式
ブール Boolean
  • True 値: true1、または同等の式
  • False 値: false0、または同等の式
選択リスト Picklist 文字列値または同等の式
複数選択リスト Multipicklist 文字列値または同等の式
日付 Date "YYYY-MM-DD" または同等の式
日付/時間 DateTime "YYYY-MM-DDThh:mm:ssZ" または同等の式
sObject sObject キー - 値ペアの対応付けまたは同等の式
1{
2     name : "varName",
3     type : "flowDataType",
4     value : valueToSet
5},
6{
7     name : "varName",
8     type : "flowDataType",
9     value : [ value1, value2] 
10}, ...

この JavaScript コントローラでは、数値変数、日付コレクション変数、および sObject 変数のペアの値を設定します。

1({
2   init : function (component) {
3      // Find the component whose aura:id is "flowData"
4      var flow = component.find("flowData");
5      var inputVariables = [
6         { name : "numVar", type : "Number", value: 30 }, 
7         { name : "dateColl", type : "String", value: [ "2016-10-27", "2017-08-01" ] },
8         // Sets values for fields in the account sObject variable. Id uses the
9         // value of the component's accountId attribute. Rating uses a string.
10         { name : "account", type : "SObject", value: {
11             "Id" : component.get("v.accountId"),
12             "Rating" : "Warm"
13             }
14          },
15          // Set the contact sObject variable to the value of the component's contact
16          // attribute. We're assuming the attribute contains the entire sObject for
17          // a contact record.
18          { name : "contact", type : "SObject", value: component.get("v.contact") }
19          },
20       ];
21       flow.startFlow("myFlow", inputVariables);
22   }
23})

次に、Apex コントローラを介して取引先を取得するコンポーネントの例を示します。Apex コントローラは、JavaScript コントローラを介してデータをフローの sObject 変数に渡します。

1<aura:component controller="AccountController" >
2   <aura:attribute name="account" type="Account" />
3   <aura:handler name="init" value="{!this}" action="{!c.init}"/>
4   <lightning:flow aura:id="flowData"/>
5</aura:component>
1public with sharing class AccountController {
2   @AuraEnabled
3   public static Account getAccount() {
4      return [SELECT Id, Name, LastModifiedDate FROM Account LIMIT 1];
5   }
6}
1({
2   init : function (component) {
3      // Create action to find an account
4      var action = component.get("c.getAccount");
5
6      // Add callback behavior for when response is received
7      action.setCallback(this, function(response) {
8         if (state === "SUCCESS") {
9            // Pass the account data into the component's account attribute 
10            component.set("v.account", response.getReturnValue());
11            // Find the component whose aura:id is "flowData"
12            var flow = component.find("flowData");
13            // Set the account sObject variable to the value of the component's 
14            // account attribute.
15            var inputVariables = [
16               {
17                  name : "account",
18                  type : "SObject",
19                  value: component.get("v.account")
20               }
21            ];
22      
23            // In the component whose aura:id is "flowData, start your flow
24            // and initialize the account sObject variable. Reference the flow's
25            // Unique Name.
26            flow.startFlow("myFlow", inputVariables);
27         }
28         else {
29            console.log("Failed to get account date.");
30         }
31      });
32
33      // Send action to be executed
34      $A.enqueueAction(action);
35   }
36})