Welcome to ExamTopics
ExamTopics Logo
- Expert Verified, Online, Free.
exam questions

Exam Certified Platform Developer II All Questions

View all questions & answers for the Certified Platform Developer II exam

Exam Certified Platform Developer II topic 1 question 16 discussion

Actual exam question from Salesforce's Certified Platform Developer II
Question #: 16
Topic #: 1
[All Certified Platform Developer II Questions]

A developer is asked to update data in an org based on new business rules. The new rules state that Accounts with the type set to 'Customer' should have a status of 'Active', and Accounts with the type set to 'Prospect' should have a status of 'Pending'. No other changes to data should be made.
Which code block will accurately meet the business requirements?

  • A. Map<String, String> statusMap = new Map<String, String>{'Customer'=>'Active', 'Prospect'=>'Pending'} List<Account> accountUpdates = new List<Account>(); for ( Account a : [SELECT Id, Type FROM Account]){ if ( statusMap.containsKey(a.Type) ) { a.Status = a.Type == 'Customer' ? 'Active' : 'Pending'; } accountUpdates.add(a); } update accountUpdates;
  • B. Map<String, String> statusMap = new Map<String, String>{'Customer'=>'Active', 'Prospect'=>'Pending'} List<Account> accountUpdates = new List<Account>(); for ( Account a : [SELECT Id, Type FROM Account WHERE Status IN :statusMap.keySet()]){ a.Status = statusMap.get(a.Type); accountUpdates.add(a); } update accountUpdates;
  • C. List<Account> accountUpdates = new List<Account>(); for ( Account a : [SELECT Id, Type FROM Account]){ if ( String.isNotBlank(a.Type) && a.Type == 'Customer' ){ a.Status = 'Active'; } if ( String.isNotBlank(a.Type) && a.Type == 'Prospect' ){ a.Status = 'Pending'; } accountUpdates.add(a); } update accountUpdades;
  • D. List<Account> accountUpdates = new List<Account>(); for ( Account a : [SELECT Id, Type FROM Account]){ a.Status = a.Type == 'Customer' ? 'Active' : 'Pending'; accountUpdates.add(a); } update accountUpdates;
Show Suggested Answer Hide Answer
Suggested Answer: A 🗳️

Comments

Chosen Answer:
This is a voting comment (?) , you can switch to a simple comment.
Switch to a voting comment New
kushalbakshi
Highly Voted 3 years, 9 months ago
This should be 'C'. D option will update all the Account records instead of only the required ones.
upvoted 11 times
...
KAALISHAN
Highly Voted 1 year, 6 months ago
Selected Answer: B
B seems to be the right answer. It has the status in the query, and does the update as required. Not sure why no one is considering B and not saying why it's wrong either!
upvoted 5 times
Sri0507
10 months, 4 weeks ago
B is not correct because in the query, filter is Status and it should be Type not Status. So it will never enter into for loop.
upvoted 1 times
...
...
beardAnt
Most Recent 1 month, 2 weeks ago
I tested the A solution and it works correctly
upvoted 1 times
...
corpex
5 months, 3 weeks ago
Selected Answer: A
A. Is correct and more optimized. With .containsKey null values are avoided. B. Is wrong because the soql is filtering by Status instead of Type, It wont receive any result C. Is correct but it less maintenable and less flexible. Mapping is a better choice. D. Is wrong because it will update all accounts with null types to Pending. In my opinion the option B was badly written in examtopics and the original exam had the soql filtering by Type which would make it perfect in terms of optimization, but in this context, A should be the correct anwser.
upvoted 2 times
...
c2ff438
7 months ago
Selected Answer: C
Should be C
upvoted 1 times
...
FriedConsole2000
9 months ago
Selected Answer: B
It is B
upvoted 1 times
...
Nikas008
1 year ago
Write answer is C, A and D can changing Accounts with other Types and B will give you not correct data because of wrong SOQL
upvoted 1 times
...
code_breaker_27
1 year, 1 month ago
Since the questoin mentioned "No other changes to data should be made", ALL answers are wrong. Query should filter Account Type IN ('Customer', 'Prospect') or should filter result if Type == Customer or Type == Prospect and only add them to the list to be updated.
upvoted 1 times
...
karappo
1 year, 8 months ago
Should be C. A will also update account with type = null or empty
upvoted 1 times
...
amilaveer
1 year, 10 months ago
All the answers are incorrect because "Status " is not in SOQL. Other than that "B" is the correct answer
upvoted 2 times
...
agjklsjrhgjksf
2 years, 5 months ago
Selected Answer: A
Only A does it all. C doesn't do second half of the task.
upvoted 4 times
...
suddeb
2 years, 8 months ago
Answer D cannot be right. This solution will fail at the 3rd line, because you would set the ‘Pending’ status for every other type than customer. Also e.g. for ‘Agency’. This means for type ‘Customer’ you would set the status ‘Active’ correctly, but for EVERY other type (Prospect, but ALSO other types) you would set the status to ‘Pending’. Answer B can’t be right as well, because the WHERE clause is filtering for “Status” IN the map’s keySet, means it checks for a status with values “Customer” or “Prospect” (which are the Account’s Type values). Therefore it will not return any account records to iterate over. C looks to me the correct answer
upvoted 3 times
...
parishk
2 years, 9 months ago
Its option B as the Account SOQL query filter only the required fields
upvoted 1 times
...
JasonZhao
2 years, 9 months ago
This should be A. Option C will increase the APEX CPU Time more than A.
upvoted 1 times
...
skipper009
2 years, 9 months ago
Does anyone notice that status wasn't included in any of the SELECT? Update on any of the choices should not work.
upvoted 1 times
...
NPW89
2 years, 12 months ago
A can be correct if where condition as follows. SELECT Id, Type FROM Account WHERE Type IN :statusMap.keySet() answer is C
upvoted 2 times
...
CraigJ
3 years, 6 months ago
While C is not ideal in it misses the else statement A assumes that there are only two options for the customer type. Crappy question.
upvoted 1 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...