//SOQL 101
Critical Limit Breach

System.LimitException:
Too many SOQL queries: 101

System.LimitException: Too many SOQL queries: 101

The classic SOQL-in-a-for-loop. Every Salesforce developer has written this pattern. It works perfectly in Sandbox with 10 test records. Then it crashes Production when real data volumes hit 1,000+ records.

12,000 developers search for this exact error every month. Most at 2:00 AM during a production incident. This page shows them exactly how Jataka catches this before the merge.

Jataka catches SOQL 101 in real-time
1:02
Watch: Developer writes SOQL in loop → Jataka blocks PRLoom Recording

The Limit: 100 SOQL queries per transaction

100

Maximum SOQL queries allowed in a single transaction

101

The query that crashes your Production at 2:00 AM

4 hrs

Average downtime from this single error

Salesforce enforces this limit to prevent runaway queries from consuming shared resources. When you hit 101, the entire transaction rolls back. If this happened in a trigger, every record in that batch fails. If it happened in a Flow, the user sees a generic error with no explanation.

The Bad Code

This code passes code review. It passes PMD. It passes SonarQube. It works in Sandbox. Then it crashes Production.

AccountTriggerHandler.cls❌ Anti-Pattern
// ❌ BAD: SOQL inside a for loop
// This works in Sandbox with 10 records
// Crashes in Production with 1,000+ records

public void processAccounts(List<Id> accountIds) {
    for (Id accId : accountIds) {
        // Each iteration runs a query!
        List<Contact> contacts = [
            SELECT Id, Name, Email
            FROM Contact
            WHERE AccountId = :accId
        ];
        
        // Process contacts...
        for (Contact c : contacts) {
            c.Email = c.Email.toLowerCase();
        }
        update contacts;
    }
}

Why static analysis misses this: PMD and SonarQube scan text. They see a query inside a loop and might flag it. But they can't know if that loop will run 5 times or 500 times. Only runtime execution reveals the truth.

Jataka Report Card

When this code runs in Jataka's Sandbox, we catch the limit breach before it ever reaches Production.

PR #247 Blocked
2 minutes ago

SOQL Queries

127/100

Query Rows

4,832/50,000

DML Statements

23/150

CPU Time

842ms/10,000ms

SOQL Limit Breach Detected

Transaction executed 127 SOQL queries. Limit is 100. Found SOQL inside for loop at line 8.

The Fix

Bulkify the query. Move it outside the loop. Process records in memory.

AccountTriggerHandler.cls✓ Bulkified
// ✅ GOOD: Bulkified query
// One query for all accounts

public void processAccounts(List<Id> accountIds) {
    // Single query outside the loop
    List<Contact> allContacts = [
        SELECT Id, Name, Email, AccountId
        FROM Contact
        WHERE AccountId IN :accountIds
    ];
    
    // Process in memory
    for (Contact c : allContacts) {
        c.Email = c.Email.toLowerCase();
    }
    
    // Single update
    update allContacts;
}

Result: 1 SOQL query instead of 127. The transaction completes in 200ms. Production stays online.

Related Anti-Patterns

Stop 2 AM firefighting

Jataka catches SOQL 101
before the merge.

Book a demo and watch Jataka block this exact error in real-time. Your developers sleep through the night.