Exam CRT-450 Topic 2 Question 127 Discussion

Actual exam question for Salesforce's CRT-450 exam
Question #: 127
Topic #: 2
The following code snippet is executed by a Lightning web component in an environment with more than
2,000 lead records:

Which governor limit will likely be exceeded within the Apex transaction?

Suggested Answer: C Vote an answer

The code snippet is likely to exceed the governor limit for the total number of records retrieved by SOQL queries. In Salesforce, there is a limit on the total number of records that can be retrieved by SOQL queries in a transaction. This limit helps in preventing the overconsumption of shared resources. If a Lightning web component tries to retrieve more than 50,000 records, it will hit this governor limit1.
The code snippet has a SOQL query inside a for loop, which is a bad practice and should be avoided. The query retrieves all the lead records with the Origin_c field, regardless of whether they are related to the current component or not. This can result in a large number of records being returned, especially if the environment has more than 2,000 lead records. The query also does not use any filters or limits to reduce the number of records. The code then updates the LeadSource field of each record and performs a DML operation inside the loop, which is another bad practice and should be avoided. The DML operation can also trigger other processes, such as workflows, triggers, or validation rules, that can consume more resources and cause other governor limits to be exceeded.
A better way to write the code would be to use a list variable to store the lead records that need to be updated, and use a SOQL query outside the loop with filters and limits to retrieve only the relevant records. Then, iterate over the list and update the LeadSource field of each record. Finally, perform a single DML operation outside the loop to update the list of records. This way, the code will reduce the number of SOQL queries and DML statements, and the number of records retrieved and processed.
References:
* Apex Governor Limits | Salesforce Developer Limits and Allocations Quick Reference | Salesforce Developers
* Apex Code Best Practices | Apex Developer Guide | Salesforce Developers
* SOQL For Loops | Apex Developer Guide | Salesforce Developers

by Arabela at Jul 30, 2026, 12:48 PM

Comments

Chosen Answer:
This is a voting comment (?) , you can switch to a simple comment.
Switch to a voting comment New
Nick name: Submit Cancel
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.

0
0
0
10