Universal Containers は注文管理アプリケーションを実装しました。各注文には、1 つ以上の注文明細項目を含めることができます。注文明細オブジェクトは、マスター詳細関係によって注文に関連付けられます。各注文明細項目の合計価格は、注文明細項目の価格と注文数量を掛けて計算されます。
注文レコードのすべての注文明細項目の合計を取得するためのベスト プラクティスは何ですか?
正解:C
To calculate the sum of all Order Line item totals on the Order record in a master-detail relationship, the best practice is to use a Roll-up Summary Field.
Roll-up Summary Field: This field type allows you to perform calculations on a set of related records, such as summing up the total price of all Order Line items related to an Order.
"Roll-up summary fields allow you to display a value in a master record based on the values of fields in a detail record."
- Salesforce Help: Define Roll-Up Summary Fields
Master-Detail Relationship: Since Order Line items are in a master-detail relationship with Orders, roll-up summary fields can be created on the master object (Order) to summarize data from the detail object (Order Line).
"You can create roll-up summary fields on any custom object that is on the master side of a master-detail relationship."
- Salesforce Developer Guide: Roll-Up Summary Fields
Why Not Other Options:
A . Quick Action: Quick actions are used to create records, log calls, send emails, etc., and are not suitable for calculating and displaying aggregate data.
B . Apex Trigger: While triggers can perform the calculation, using them for this purpose is not considered best practice when declarative solutions like roll-up summary fields are available.
"Use declarative functionality (roll-up summary fields) for maintaining aggregates instead of triggers."
- Salesforce Developer Guide: Best Practices for Triggers
D . Formula Field: Formula fields cannot aggregate data from child records to parent records unless they are part of a roll-up summary field in a master-detail relationship.
Conclusion: Using a roll-up summary field is the most efficient and recommended approach to sum the total prices of all Order Line items on the Order record.