Allow Reparenting in Master-Detail Relationships: In a master-detail relationship, the child record (in this case, OrderItem) is tightly bound to the parent record (Order). By default, child records cannot be reassigned to a different parent record in master-detail relationships. However, enabling the"Allow Reparenting"option on the master-detail field allows the child record (OrderItem) to be reparented to a different master record (Order). This is the correct solution as it ensures that OrderItem records can be reassigned to a new Order without changing the structure of the relationship. Why not the other options? A). Add without sharing to the Apex class declaration: Adding without sharing modifies sharing rules but does not affect the ability to reparent child records. This is unrelated to the issue described. B). Change the master-detail relationship to an external lookup relationship: Changing the relationship type is not necessary. Additionally, doing so could introduce unintended side effects, as master-detail relationships have features like roll-up summaries that are lost with a lookup relationship. C). Create a junction object between OrderItem and Order: Introducing a junction object is not required. This adds unnecessary complexity and deviates from the intended use of master-detail relationships. References: Master-Detail Relationship Documentation Allow Reparenting Option
最新のコメント (最新のコメントはトップにあります。)
正解は **D** です。
この問題の日本語訳にある「再印刷」は、英語の **"Reparenting"(リペアレンティング:親の付け替え)** の誤訳です。正しくは「親の変更を許可する」という意味です。
### 領域の確認
* **領域:** **1. 開発者の基本 (Developer Fundamentals)**
* **トピック:** データモデリング、マスター詳細関係 (Master-Detail Relationship)
---
### 正解の解説
**D. マスター詳細関係の再印刷(親の変更 / Allow reparenting)を許可するオプションを選択します。**
Salesforceの **マスター詳細関係 (Master-Detail Relationship)** には、非常に重要なルールがあります。
1. **デフォルトの挙動:**
一度子レコード(OrderItem)を作成して親(Order)に紐付けると、**後から親を変更することはできません**。Apexコードで `OrderId` を書き換えて `update` しようとしてもエラーになります。
2. **解決策:**
`OrderItem` オブジェクトにあるマスター詳細関係項目の定義設定で、**「親の変更を許可 (Allow reparenting)」** というチェックボックスをオンにします。
この設定を有効にすることで、初めてApexコードやAPIを使用して、子レコードを別の親レコードへ移動(OrderIdの更新)させることが可能になります。
---
### 不正解の解説
**A. Apex クラス宣言に共有せず (without sharing) に追加します。**
これは **不正解** です。
`without sharing` は「ユーザのレコードアクセス権限(共有ルール)」を無視してシステムモードで実行するための宣言です。
しかし、マスター詳細関係の「親を変更できない」という制約は、アクセス権限ではなく**データモデルの構造上の制約**です。いくらシステムモードで実行しても、データモデル側でDの設定が許可されていなければエラーになります。
**B. マスター詳細関係を外部参照関係 (Lookup) に変更します。**
これは **不正解** です。
参照関係にすれば親の変更は自由にできるようになりますが、マスター詳細関係特有の機能(積み上げ集計項目、連鎖削除、セキュリティの継承など)が失われてしまいます。
要件を満たすためにデータモデルの種類を変える必要はなく、設定オプション(D)を変更するだけで十分です。
**C. OrderItem と Order の間にジャンクション オブジェクトを作成します。**
これは **不正解** です。
ジャンクションオブジェクトは「多...