Salesforce Platform Developer Practice Exam 2025 – All-in-One Guide to Ace Your Certification!

Image Description

Question: 1 / 400

A developer's code fails when inserting 10,000 Lead records due to a query inside a loop. What line of code is causing the failure?

Line-01: For loop structure

Line-02: PostalCode null check

Line-03: SOQL query inside for loop

The code is failing because a SOQL query is being executed inside a for loop. In Salesforce, governor limits restrict the number of SOQL queries that can be run in a single transaction to a maximum of 100. When the developer attempts to insert 10,000 Lead records and includes a SOQL query in each iteration of the loop, the system exceeds the allowed limit of SOQL queries, leading to a governor limit exception.

To avoid this situation, it is best practice to perform SOQL queries outside of loops. Instead of querying within the loop, you would typically gather all necessary data beforehand and store it in a collection such as a list or a map. This allows you to process records efficiently while remaining within Salesforce's governor limits, ensuring that the code can handle the bulk insert without failure.

The other aspects mentioned—such as the for loop structure, null checks, and updating records—do not inherently violate governor limits and typically would not be the direct cause of the failure in this scenario.

Get further explanation with Examzify DeepDiveBeta

Line-05: Updating Lead in before insert

Next Question

Report this question

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy