//Lock Contention
High Severity Limit Breach

System.DmlException:
UNABLE_TO_LOCK_ROW

System.DmlException: UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record

Data skew. Your top Account has 50,000 Contacts. Two users try to update the same parent field simultaneously. Lock contention brings your org to a halt. The whole system freezes waiting for a lock that never releases.

2,400 developers search for this error every month. It's the silent killer of enterprise Salesforce orgs—data skew accumulates over years until one day, everything locks up.

Jataka detects data skew in real-time
1:08
Watch: Data skew detected → Jataka warns before lockLoom Recording

The Problem: Data Skew

Data skew occurs when a single parent record has more than 10,000 child records. Salesforce's locking mechanism can't handle concurrent updates to the same parent when thousands of children are involved. The result: lock timeouts, failed updates, and angry users.

Account-Contact

10,000+

Parent record lock contention

Account-Opportunity

10,000+

Sharing recalculation timeout

Custom Object-Parent

10,000+

Query performance degradation

8 hrs

Average downtime from lock contention incidents

5-10s

Lock wait timeout before the error is thrown

0

Tools that detect data skew before deployment

The Bad Code

Explicit locking on a parent record with 50,000 children. A recipe for lock contention disaster.

AccountUpdateTriggerHandler.cls❌ Anti-Pattern
// ❌ BAD: Updating parent record when children have data skew
// Top Account has 50,000+ Contacts (data skew)

public void updateAccountIndustry(List<Contact> contacts) {
    Set<Id> accountIds = new Set<Id>();
    for (Contact c : contacts) {
        accountIds.add(c.AccountId);
    }
    
    // Lock contention on Account with 50,000 children
    List<Account> accounts = [
        SELECT Id, Industry 
        FROM Account 
        WHERE Id IN :accountIds
        FOR UPDATE  // ❌ Lock wait timeout!
    ];
    
    for (Account acc : accounts) {
        acc.Industry = 'Technology';
    }
    update accounts;
}

Why this is dangerous: When multiple users or processes try to lock the same skewed parent record, Salesforce can't acquire the lock within the 5-10 second timeout. The transaction fails, and if this is in a trigger, every record in the batch fails.

Jataka Report Card

Jataka's data skew analyzer detects parent records with excessive child counts and warns before lock contention occurs.

PR #589 Warning
15 minutes ago

Data Skew Detected

Parent record has excessive child records. Lock contention risk high.

Account: Acme Corp52,847 Contacts
Lock Wait RiskHIGH

Recommendation: Remove FOR UPDATE clause or use async processing to avoid concurrent lock attempts on this skewed parent record.

The Fix

Avoid explicit locking on skewed parent records. Use selective updates or async processing.

AccountUpdateTriggerHandler.cls✓ Fixed
// ✅ GOOD: Avoid locking skewed parent records
// Use selective updates without parent locking

public void updateAccountIndustry(List<Contact> contacts) {
    Set<Id> accountIds = new Set<Id>();
    for (Contact c : contacts) {
        accountIds.add(c.AccountId);
    }
    
    // Update without explicit lock
    List<Account> accounts = [
        SELECT Id, Industry 
        FROM Account 
        WHERE Id IN :accountIds
        // No FOR UPDATE - let Salesforce handle locking
    ];
    
    // Batch updates to reduce contention
    Database.update(accounts, false); // Partial success allowed
    
    // Or: Use async processing for high-volume updates
    // System.enqueueJob(new AccountUpdateJob(accounts));
}

Result: No explicit lock on parent. Updates proceed without contention. Partial success mode allows individual record failures without blocking the entire batch.

Related Anti-Patterns

Detect data skew before it locks

Jataka detects lock contention risk
before the merge.

Book a demo and watch Jataka analyze your data model for skew. Your org stays fast under load.