0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

新規作成したレコードのIdを取得する方法 フロー

Last updated at Posted at 2023-08-31

1件のレコードをInsert した場合

「変数を手動で割り当てる」オプション (オレンジ色の丸で囲んだ部分)を使って、Idを得ることが可能です

image.png

Apexなら

Account acct = new Account(Name='SFDC Account');
insert acct;

system.debug("Inserted Account Id = "+acct.Id);

コレクション変数を使って一括insertした場合

[レコードのすべての値を使用する] オプションを使用して新しいレコードを作成した場合、その後、 [Create] 要素で使用される元の変数を参照することによって、新しく作成されたレコードのレコード ID を参照できます。以下のスクリーンショットでは、Opportunity の作成に使用される変数が「OpptoCreate」という名前であることがわかります。次に、次のスクリーンショットでは、変数「OpptoCreate」から商談 ID を参照する商談連絡先ロールを作成しています。

この例だとおそらく最初の1件目しかIdはとれないと思う。

image.png

image.png

一括新規作成した場合にIdを取得するには

以下のように複数更新したら、このコレクション変数にIdがちゃんと入っているということでした。

image.png

このコレクション変数でループを作って、中身を確かめたらちゃんとIdがありましたね。

image.png

今まで試したことはないですが、Apexの一括更新で insert insertAccList とリスト変数で一括作成した後にはこのList変数にIdがちゃんと入っているかもしれなですね。

考えてみれば、これと挙動は変わらんだろう。

Account acct = new Account(Name='SFDC Account');
insert acct;

system.debug("Inserted Account Id = "+acct.Id);

資料

0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?