Plat-Dev-201 practice question 27 of 30
An Opportunity needs to have an amount rolled up from a custom object that is not in a master- detail relationship. How can this be achieved?
Full set: 204 questionsStandard roll-up summary fields only function across master-detail relationships. To replicate this functionality for a lookup relationship, an Apex trigger is the appropriate solution. The trigger should be placed on the child object. When a child record is created, updated, deleted, or undeleted, the trigger fires. Inside the trigger, an aggregate SOQL query (e.g., SELECT SUM(Amountc) FROM Childc WHERE Opportunityc = :oppId) can calculate the new total for the parent Opportunity and update a custom field on it.
A. A trigger on the parent (Opportunity) object will not fire when a child record is modified, so it cannot react to changes that require a roll-up recalculation.
B. The Streaming API is a notification service for pushing data changes to external clients; it is not used for server-side data aggregation.
D. The Metadata API is used for deploying and retrieving an org's customizations (metadata), not for performing data-level calculations.
Salesforce Apex Developer Guide, "Triggers". "Triggers can be used to perform custom actions before or after changes to Salesforce records, such as insertions, updates, or deletions."
Salesforce Apex Developer Guide, "Working with SOQL Aggregate Functions". "Use aggregate functions in a GROUP BY clause in SOQL queries to generate reports for analysis... Common functions include SUM() and COUNT()." This is the mechanism used within the trigger.
Trailhead by Salesforce, "Apex Triggers" module, "Trigger Apex". This module explains how triggers respond to DML events, which is the foundation for this roll-up pattern.
Keep practicing
Take the free Plat-Dev-201 practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other Plat-Dev-201 practice questions
- Question 1Which three steps allow a custom Scalable Vector Graphic (SVG) to be included in a Lightn…
- Question 2Which two statements are true about using the @testSetup annotation in an Apex test class…
- Question 3Managers at Universal Containers want to ensure that only decommissioned containers are a…
- Question 4Universal Containers has a Visualforce page that displays a table of every Container__c b…
- Question 5A developer is alerted to an issue with a custom Apex trigger that is causing records to …
- Question 6Which two operations affect the number of times a trigger can fire? Choose 2 answers
