Deal of The Day! Hurry Up, Grab the Special Discount - Save 25% - Ends In 00:00:00 Coupon code: SAVE25
Welcome to Pass4Success

- Free Preparation Discussions

Salesforce Certified Platform Developer II (Plat-Dev-301) Exam - Topic 2 Question 125 Discussion

Which two best practices should the developer implement to optimize this code? Choose 2 answers
C) Use a collection for the DML statement. and D) Query the Driving-Structure_C records outside of the loop
A) Change the trigger context to after update, after insert
B) Remove the DML statement.

Salesforce Certified Platform Developer II (Plat-Dev-301) Exam - Topic 2 Question 125 Discussion

Actual exam question for Salesforce's Salesforce Certified Platform Developer II (Plat-Dev-301) exam
Question #: 125
Topic #: 2
[All Salesforce Certified Platform Developer II (Plat-Dev-301) Questions]

Which two best practices should the developer implement to optimize this code? Choose 2 answers

Show Suggested Answer Hide Answer
Suggested Answer: C, D

To optimize the code in question, it's important to follow best practices that reduce the number of SOQL queries and DML statements within loops, as these can quickly consume governor limits and lead to inefficiencies. Option C is correct because using a collection to hold records and performing a single DML operation outside of loops reduces the number of DML operations, which is a best practice for bulkifying code in Salesforce. Option D is also correct because querying records outside of a loop prevents hitting SOQL governor limits and makes the code more efficient. Options A and B are not correct in the context provided, as there isn't enough information to determine if changing the trigger context is necessary, and removing the DML statement altogether may not be feasible if the logic requires data to be persisted.

Reference

Apex Best Practices: Apex Developer Guide Best Practices


Contribute your Thoughts:

0/2000 characters
Kaycee
24 days ago
I agree, collections are the way to go!
upvoted 0 times
...
Tarra
29 days ago
Wait, removing the DML statement? That seems risky.
upvoted 0 times
...
Daron
1 month ago
I think A is also a good choice.
upvoted 0 times
...
Laura
1 month ago
Definitely go with C and D!
upvoted 0 times
...
Brianne
1 month ago
I practiced a similar question, and I think removing the DML statement might not be the best choice. We usually need it to save changes, right?
upvoted 0 times
...
Brittani
2 months ago
I feel like querying the Driving-Structure_C records outside of the loop is important too. It reduces the number of queries, which is a common optimization technique.
upvoted 0 times
...
Annice
2 months ago
I'm not so sure about the trigger context. I remember something about using after update, but I can't recall if it applies here.
upvoted 0 times
...
Roslyn
2 months ago
I think using a collection for the DML statement is definitely a best practice. It helps with bulk processing, right?
upvoted 0 times
...
Shakira
2 months ago
I practiced a similar question where using collections was key, so I’m leaning towards C for sure!
upvoted 0 times
...
Ceola
2 months ago
I feel like changing the trigger context could help, but I’m not entirely confident if it’s the best choice here.
upvoted 0 times
...
Dudley
3 months ago
I remember something about querying outside of loops being a best practice, so maybe option D is correct?
upvoted 0 times
...
Jamal
3 months ago
I think using a collection for the DML statement is definitely a good practice, but I'm not sure about the other option.
upvoted 0 times
...

Save Cancel