Certified Platform Developer II Practice Test

Certified Platform Developer II Practice Test practice questions, page 10 of 17, with answer review and explanations.

Question 46

Business rules require a Contact to always be created when a new Account is created. What can be used when developing a custom screen to ensure an Account is not created if the creation of the Contact fails?

  1. Use the Database.Delete method if the Contact insertion fails.
  2. Use the Database.Insert method with allOrNone set to False.
  3. Disable Validation rules on Contacts and set default values with a Trigger.
  4. Use setSavePoint() and rollback() with a try/catch block.

Question 47

trigger AssignOwnerByRegion on Account ( before insert, before update ) { List accountList = new List (); for( Account anAccount : trigger.new ) { Region__c theRegion = [ SELECT Id, Name, Region_Manager__c FROM Region__c - WHERE Name = :anAccount.Region_Name__c ]; anAccount.OwnerId = theRegion.Region_Manager__c; accountList.add( anAccount ); } update accountList; } Consider the above trigger intended to assign the Account to the manager of the Account's region. Which two changes should a developer make in this trigger to adhere to best practices? (Choose two.)

  1. Use a Map to cache the results of the Region__c query by Id.
  2. Move the Region__c query to outside the loop.
  3. Remove the last line updating accountList as it is not needed.
  4. Use a Map accountMap instead of List accountList.

Question 48

Example 1: AggregateResult[] groupedResults = [SELECT CampaignId, AVG(Amount) FROM Opportunity GROUP BY CampaignId]; for (AggregateResult ar : groupedResults) { System.debug('Campaign ID' + ar.get('CampaignId')); System.debug('Average amount' + ar.get('expr0')); } Example 2: AggregateResult[] groupedResults = [SELECT CampaignId, AVG(Amount) theAverage FROM Opportunity GROUP BY CampaignId]; for (AggregateResult ar : groupedResults) { System.debug('Campaign ID' + ar.get('CampaignId')); System.debug('Average amount' + ar.get('theAverage')); } Example 3: AggregateResult[] groupedResults = [SELECT CampaignId, AVG(Amount) FROM Opportunity GROUP BY CampaignId]; for (AggregateResult ar : groupedResults) { System.debug('Campaign ID' + ar.get('CampaignId')); System.debug('Average amount' + ar.get.AVG()); } Example 4: AggregateResult[] groupedResults = [SELECT CampaignId, AVG(Amount) theAverage FROM Opportunity GROUP BY CampaignId]; for (AggregateResult ar : groupedResults) { System.debug('Campaign ID' + ar.get('CampaignId')); System.debug ('Average amount' + ar.theAverage); } Which two of the examples above have correct System.debug statements? (Choose two.)

  1. Example 1
  2. Example 2
  3. Example 3
  4. Example 4

Question 49

Which method should be used to convert a Date to a String in the current user's locale?

  1. Date.format
  2. String.format
  3. String.valueOf
  4. Date.parse

Question 50

A company has a custom object, Order__c, that has a required, unique, external ID field called Order_Number__c. Which statement should be used to perform the DML necessary to insert new records and update existing records in a List of Order__c records?

  1. upsert orders;
  2. upsert orders Order_Number__c;
  3. merge orders Order_Number__c;
  4. merge orders;