LoginSignup
0
1

More than 1 year has passed since last update.

Apex を呼び出すフロー、コレクション変数を渡すことができません

Last updated at Posted at 2022-12-02

入力パラメータをList型で定義していますが、フローから呼び出そうとするとコレクション変数が選択できないですね。
困った。だからフローは使いたくない。 ヘルプを見てコードを書いたけど機能しない。

@InvocableMethod(label='sendRport')
    public static List<String>  test004(List<String> inputStringList) {

image.png

1日探して回答かなぁって思ったけど違う。
Flow calling Apex, can't pass Collection Variable

Listを重ねた不細工な定義しましたが、コレクション変数は出てきませんね。

@InvocableMethod(label='sendRport')
    public static List<String>  test004(List<List<String>> inputStringList) {

このようにはならんなぁ
How to pass Salesforce Flow variables into Apex Class with correct scope?

一旦フローの編集ページを抜けて、再度開いて確かめたら、おおおお出てきたよ。やっと。
image.png

しかし、以下の「入力で使用可能」の設定がないとエラーになりました。

image.png


There can be at most one input parameter and its data type must be a list of the following: primitive data type, sObject type, generis sObject type, user-defined type containing variables of the supported types above, or user-defined Apex types.

sObjectならできる?

@InvocableMethod(label='sendRport')
    public static List<String>  test004(List<sObject> inputStringList) {

ああああ、できませんね。選択できるのがオブジェクトになっただけ。

image.png

結果数は、1 つの一括実行要求で実行されたインタビュー数と一致しません。

コレクション変数を渡せるようになったので、Apexの中でメールを複数送信してみました。
どうもフローのApexアクションの中でメールを送信できるのは1通だけかもしれませんね。

シングルメールがダメかな?

Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();     
EmailService service = new EmailService(email);

英語のエラーメッセージで言えば、これのようです。

The number of results does not match the number of interviews that were executed in a single bulk execution request.

Flow Error: The number of results does not match ....

この回答を読むと入力でList変数のサイズが2なら、出力でもList変数のサイズは2にしないといけないようです。
入力と出力のサイズを同じにする必要がありますです。

I believe the error was on the input parameter being an sobject not a list . Changing the request type and the logic within the method to handle list of sobjects did the trick!

しかし、リストの結果はサイズ2を返しているけどエラーになりますね。よく分からん。

解決方法がみつかりました。

Apexのコードですが入力時の変数はフローから見てコレクション変数として扱えるように**List>**と定義していましたが、戻り値は**List**でした。 入力と同じように**List>**で返すと、このエラーは無くなりました。
入力と出力の変数の型をそろえておくということでしょうか?

恰好悪ですが、以下のように複数のApexアクションを書けば動きました。Maxがあるかとやってみましたが6アクションでも問題ないようです。

image.png

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1