Skip to main content
SFDC Developers
Admin

Salesforce Data Skew: Remediation Strategies

Vinay Vernekar · · 6 min read

You've inherited a Salesforce org. Documentation is sparse, user complaints about slow page loads, locking errors, and never-ending sharing recalculations are mounting. After investigation, the culprit is identified: data skew, silently accumulating for years and now severely impacting performance.

While many resources focus on preventing data skew during initial org design, this article addresses the reality of inheriting a production org with established skew issues. We will cover how to identify skew in production, quantify its severity, prioritize remediation efforts, and implement fixes without introducing new problems.

Understanding Data Skew

Data skew in Salesforce occurs when an excessive number of records are associated with a single parent record, owned by a single user or queue, or linked via a lookup field. This imbalance concentrates data, leading to performance bottlenecks.

There are three primary types of data skew:

  • Account Data Skew: Thousands of child records (Contacts, Opportunities, Cases, etc.) are linked to a single Account. This can cause record locking during DML operations and disrupt bulk data loads.
  • Ownership Skew: A single user or queue owns a disproportionately large number of records across an object. In private sharing models, changes to ownership, roles, or territories can trigger extensive sharing recalculations.
  • Lookup Skew: Numerous records reference the same record via a lookup field. Similar to account skew, this can lead to contention and locking issues.

Observable symptoms often include:

  • UNABLE_TO_LOCK_ROW errors during data loads.
  • Sharing recalculations taking hours.
  • Slow loading of specific record pages.
  • Integration failures tied to certain records.
  • Apex batch jobs timing out on queries.

Many seemingly disparate performance issues can stem from data skew.

Step 1: Diagnose and Quantify Skew

Before addressing skew, you must understand its scope. Quantifying it is crucial for prioritization and gaining stakeholder buy-in.

Detecting Account Data Skew

Use SOQL queries in the Developer Console or Workbench to identify skewed accounts. For example:

SELECT AccountId, COUNT(Id) childCount FROM Contact GROUP BY AccountId ORDER BY childCount DESC LIMIT 20

Run similar queries for Opportunities, Cases, and any custom objects with lookups or master-detail relationships to Account. Salesforce generally considers 10,000 child records per parent as a threshold where performance issues can emerge, with anything over 50,000 being critical.

Detecting Ownership Skew

Query for record ownership distribution:

SELECT OwnerId, COUNT(Id) recordCount FROM Opportunity GROUP BY OwnerId ORDER BY recordCount DESC LIMIT 20

Pay close attention to system integration users, queues, and users acting as automated process owners. A single user or queue owning over 10,000 records in a private or controlled sharing model indicates ownership skew.

Checking for Sharing Recalculation Delays

Navigate to Setup > Defer Sharing Calculations. Repeated enablement of this setting strongly suggests recurrent sharing recalculation problems. The Setup Audit Trail can confirm how frequently it has been toggled.

Also, check Setup > Background Jobs for any long-running or stalled sharing recalculation jobs. Jobs exceeding a few hours require immediate attention.

Step 2: Prioritize Remediation Efforts

Resist the urge to fix all skew immediately. Prioritize based on business impact and remediation risk:

  • Fix First: Skew actively causing production errors (UNABLE_TO_LOCK_ROW, stuck sharing recalculations, timing out reports). These have direct, measurable business consequences.
  • Fix Next: Ownership skew affecting users slated for deactivation, role changes, or territory assignments. These are potential catalysts for major org-wide sharing recalculations.
  • Monitor and Document: Skew that exists but isn't currently causing problems. Log it, establish thresholds, and revisit periodically (e.g., quarterly). Not all skew requires immediate intervention.

Step 3: Secure Leadership Buy-In

Remediation of data skew is often invisible, time-consuming, and carries risk. To gain support:

  • Translate Errors into Cost: Quantify the impact of errors. For example, "Our nightly sync fails 3-4 times weekly due to locking issues on the Acme account, each requiring 45 minutes of engineering time for a manual re-run."
  • Use the 'Time Bomb' Framing: "Deactivating or reassigning the integration user will trigger a sharing recalculation on 80,000 records, potentially locking the org for 4-6 hours during business hours."
  • Tie to Upcoming Projects: Frame skew remediation as a risk mitigation strategy for upcoming initiatives like data migrations, Agentforce rollouts, or new integrations.

Step 4: Remediation Strategies

Effective remediation depends on the type and severity of skew.

For Account Data Skew

  • Split the Parent Account: For accounts with tens of thousands of children (e.g., "Household" or "Global" accounts), consider splitting them into more granular sub-accounts (regional, business unit). This is a data model change requiring stakeholder approval but offers a robust long-term solution.
  • Archive Historical Records: Bulk-archive or soft-delete inactive or old child records. This significantly reduces the child count without altering the core data model.
  • Utilize Big Objects for Historical Data: Move high-volume, historical data (e.g., closed cases, old activities) to Salesforce Big Objects. This removes them from standard object skew calculations.

For Ownership Skew

  • Reassign Records in Batches: Use Data Loader or a scheduled Flow to gradually reassign records from overloaded owners. Perform these operations during off-peak hours in batches of 2,000 records or fewer to minimize the risk of mass sharing recalculations.
  • Use Defer Sharing Calculations Deliberately: For unavoidable large reassignments, suspend sharing recalculations via Setup > Defer Sharing Calculations. Resume and complete recalculations during scheduled maintenance windows. This feature is designed for such scenarios.
  • Flatten Role Hierarchies: Deep role hierarchies amplify ownership skew impact. Flattening hierarchies can reduce the scope of sharing calculation cascades resulting from role changes.

Step 5: Monitor to Prevent Regression

Continuous monitoring is essential to prevent skew from reappearing.

  • Schedule a Monthly SOQL Audit: Automate the child-record-count queries using scheduled Apex or a Flow that logs results to a custom object. Create a dashboard to track the top accounts by child count over time.
  • Set Threshold Alerts: Implement a Flow or Apex trigger to notify the admin team when account or owner record counts exceed predefined thresholds (e.g., 8,000 child records). Addressing skew early is far more manageable.
  • Document Findings and Fixes: Maintain a change log (in a wiki, Confluence, or custom object) detailing identified skew issues, remediation steps taken, and dates. This documentation is invaluable for future reference.

Key Takeaways

  • Data skew in production Salesforce orgs requires a systematic approach to diagnosis, prioritization, and remediation.
  • Quantify skew using SOQL queries to understand the scale of account, ownership, and lookup issues.
  • Prioritize fixes based on active business impact and the risk of future problems.
  • Effectively communicate the business value of seemingly invisible work to stakeholders by translating technical issues into costs and risks.
  • Implement targeted remediation strategies such as splitting accounts, archiving data, reassigning records in batches, and leveraging features like Defer Sharing Calculations.
  • Establish ongoing monitoring through scheduled audits and threshold alerts to prevent skew from recurring. Document all remediation efforts for future reference.

Share this article

Get weekly Salesforce dev tutorials in your inbox

Comments

Loading comments...

Leave a Comment

Trending Now