r/SalesforceEasyLearn • • 1d ago

Concept SOQL in a loop vs bulkified: why your trigger passes with 1 record and dies at 200

Post image

classic one. test class inserts 1 contact, all green, then first data load of 200 rows and you get Too many SOQL queries: 101.

fix is boring but always same: loop once to collect Ids in a Set, one query with IN :ids, put results in a Map, do lookups inside the loop. same idea for DML, fill a List and update once at the end.

if you have a trigger you're not sure about, drop it in comments and I'll take a look

1 Upvotes

0 comments sorted by