オブジェクトのリストは重複値を保持できますが、リスト内の Object ID が重複した状態で更新または削除しようとすると、「System.ListException: Duplicate id in list」というエラーが表示されます。
サンプルコード
// salesforce 組織から Id を選びます。この例では取引先の Id を選びます。
Id aid = '0017F000002WkkdQAC'; list <account> al = new list <account>(); for(account a : [select id from account where Id ='0017F000002WkkdQAC']){ account acc = new account(Id = aid); al.add(a); al.add(acc); }
// リストの値を保持するマップを作成します。 map<id,account> accmap = new map<id,account>(); // リストの値をすべてマップに入れます。 accmap.putall(al); if(accmap.size()>0){ update accmap.values(); }
List クラス
Map クラス
免責事項: これはエラーを解決する方法の一例であり、唯一の方法ではありません。本番にリリースする前に、必要に応じて Sandbox でテストしてください。
000382864

We use three kinds of cookies on our websites: required, functional, and advertising. You can choose whether functional and advertising cookies apply. Click on the different cookie categories to find out more about each category and to change the default settings.
Privacy Statement
Required cookies are necessary for basic website functionality. Some examples include: session cookies needed to transmit the website, authentication cookies, and security cookies.
Functional cookies enhance functions, performance, and services on the website. Some examples include: cookies used to analyze site traffic, cookies used for market research, and cookies used to display advertising that is not directed to a particular individual.
Advertising cookies track activity across websites in order to understand a viewer’s interests, and direct them specific marketing. Some examples include: cookies used for remarketing, or interest-based advertising.