When an Account's custom picklist field called Customer Sentiment is changed to a value of "Confused", a new related Case should automatically be created. Which two methods should a developer use to create this case? (Choose two.)
Correct Answer: A,C
Question 7
Which two statements are true about using the @testSetup annotation in an Apex test class? Choose 2 answers
Correct Answer: B,D
* B: @testSetup inserts data once and shares it across all test methods in the class, saving system resources. * D: @isTest(SeeAllData=true) is incompatible with @testSetup due to their differing purposes for managing test data.
Question 8
Which query should a developer use to obtain the Id and Name of all the Leads, Accounts, and Contacts that have the company name "Universal Containers"?
Correct Answer: D
Question 9
A software company is using Salesforce to track the companies they sell their software to in the Account object. They also use Salesforce to track bugs in their software with a custom object, Bug__c. As part of a process improvement initiative, they want to be able to report on which companies have reported which bugs. Each company should be able to report multiple bugs and bugs can also be reported by multiple companies. What is needed to allow this reporting?
Correct Answer: A
The requirement is to model a many-to-many relationship between Account and Bug__c: Each Account (company) can report multiple bugs. Each Bug__c can be reported by multiple accounts. To represent a many-to-many relationship in Salesforce, we use a junction object. Option A: Junction object between Bug__c and Account Correct Answer. Create a custom junction object, e.g., AccountBug__c, with two master-detail relationships: One to Account. One to Bug__c. This allows linking accounts and bugs in a many-to-many fashion. Enables reporting on which companies have reported which bugs. This would create a one-to-many relationship (one account to many bugs), but a bug cannot be associated with multiple accounts. Option C: Lookup field on Bug__c to Account Incorrect. Similar to Option B, it creates a one-to-many relationship. Option D: Roll-up summary field of Bug__c on Account Incorrect. Roll-up summary fields require a master-detail relationship. Does not address the many-to-many requirement. Conclusion: To allow reporting on the many-to-many relationship, a junction object between Bug__c and Account is needed, which is Option A. Reference: Creating Many-to-Many Relationships Incorrect Options: Option B: Master-detail field on Bug__c to Account Incorrect.
Question 10
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?
Correct Answer: B
When an Opportunity needs to have an amount rolled up from a custom object that is not in a master-detail relationship, the best approach is to: Option B: Write a trigger on the child object and use an aggregate function to sum the amount for all related child objects under the Opportunity. Roll-Up Summary Fields Limitation: Roll-up summary fields can only be created on master-detail relationships. Since the custom object is in a lookup relationship with Opportunity (not master-detail), roll-up summary fields are not available. "Roll-up summary fields can only be created on master-detail relationships." - Salesforce Help: Define Roll-Up Summary Fields Trigger on Child Object: Writing a trigger on the child object (the custom object) allows you to execute logic whenever a child record is inserted, updated, or deleted. Aggregate Function: Within the trigger, you can use SOQL aggregate functions (like SUM()) to calculate the total amount of all child records related to the Opportunity and update the parent Opportunity record accordingly. trigger ChildObjectTrigger on ChildObject__c (after insert, after update, after delete, after undelete) { Set<Id> oppIds = new Set<Id>(); if(Trigger.isInsert || Trigger.isUpdate || Trigger.isUndelete){ for(ChildObject__c child : Trigger.new){ oppIds.add(child.Opportunity__c); } } if(Trigger.isDelete){ for(ChildObject__c child : Trigger.old){ oppIds.add(child.Opportunity__c); } } List<Opportunity> oppsToUpdate = new List<Opportunity>(); for(Id oppId : oppIds){ Decimal totalAmount = [SELECT SUM(Amount__c) FROM ChildObject__c WHERE Opportunity__c = :oppId]; Opportunity opp = new Opportunity(Id = oppId, Total_Child_Amount__c = totalAmount); oppsToUpdate.add(opp); } update oppsToUpdate; } Why Other Options Are Incorrect: Option A: Use the Streaming API to create real-time roll-up summaries. The Streaming API is designed for receiving notifications of data changes in Salesforce and is not suitable for calculating roll-up summaries. "The Streaming API enables streaming of events using push technology and provides a subscription mechanism for receiving events in near real time." - Salesforce Developer Guide: Streaming API Option C: Use the Metadata API to create real-time roll-up summaries. The Metadata API is used for deploying and retrieving metadata (like custom fields, layouts) between orgs and does not perform data calculations. "Use Metadata API to retrieve, deploy, create, update, or delete customization information, such as custom object definitions and page layouts, for your org." - Salesforce Developer Guide: Metadata API Option D: Write a trigger on the Opportunity object and use tree sorting to sum the amount for all related child objects under the Opportunity. Writing a trigger on the Opportunity object would not effectively capture changes made to child records, as triggers on the parent do not fire when child records are modified. Tree sorting is not a standard technique in Apex for summing related records. Conclusion: Writing a trigger on the child object is the most effective way to sum amounts from child records and update the parent Opportunity when a master-detail relationship is not present.