What is the best practice to get the sum of all Order Line item totals on the Order record?
Universal Containers has implemented an order management application. Each Order can have one or more Order Line items. The Order Line object is related to the Order via a master-detail relationship. For each Order Line item, the total price is calculated by multiplying the Order Line item price with the quantity ordered.
What is the best practice to get the sum of all Order Line item totals on the Order record?
A. Quick action
B. Apex trigger
C. Roll-up summary field
D. Formula field
Answer: C
Explanation:
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.
Latest DEX-450 Dumps Valid Version with 456 Q&As
Latest And Valid Q&A | Instant Download | Once Fail, Full Refund