Which line of code is causing the code block to fail? A developer - ProProfs Discuss
Topics
Products
Follow Us:

Which line of code is causing the code block to fail? A developer uses a before insert trigger on the Lead object to fetch the Territory__c object, where the Territory__c.PostalCode__c matches the Lead.PostalCode. The code fails when the developer uses the Apex Data Loader to insert 10,000 Lead records. The developer has the following code block: Line-01: for (Lead l : Trigger.new){Line-02: if (l.PostalCode != null){Line-03: List terrList = [SELECT ID FROM Territory__c WHERE PostalCode__c = :l.PostalCod;Line-04: if(terrList.size() > 0)Line-05: l.Territory__c = terrList[.ID; Line-06: }Line-07: }

This question is part of Dev I(401) Red
Asked by Zslaykz, Last updated: Feb 04, 2020

+ Answer
Request

2 Answers

topete

Topete

Answered Dec 30, 2019

Why is the correct answer Line -01 if here that user is using trigger.new in a before insert trigger.

 

zslaykz

Zslaykz

Answered Jan 30, 2019

Line-03: A SOQL query is located inside of the for loop code.
Line-01: Trigger:new is not valid in a before insert Trigger.
 

Search for Google images
Select a recommended image
Upload from your computer
Search for Google images
Select a recommended image
Upload from your computer
Search for Google images
Select a recommended image
Upload from your computer

Email Sent
We have sent an email to your address "" with instructions to reset your password.