Skip to main content

SLAM_load_lockbuster

Overview​

LockBuster is a specialized data loading procedure that eliminates lock issues commonly experienced with bulk loads while also optimizing for speed. These lock errors are a direct result of the relationships on the object.

LockBuster is as simple to use as any other data loading procedure. It only requires the user to provide the relationships that may cause locking.

tip

When to use LockBuster

LockBuster can be used at any time, but excels in any of these situations:

  • High data skew, OR
  • Junction objects, OR
  • Objects with master-detail relationships, OR
  • When the object is included in roll-up style calculations on related records

LockBuster creates its own sorting data. It adds a Sort column and a SLAM_job column to the input table, replacing any columns with those names. The load then sends rows in Sort order, as described in Row Order and the Sort Column. Any Sort values you supplied are overwritten.

We recommend trying LockBuster when you have roughly 100,000 or more records to load.

Data skew in Salesforce occurs when there are large quantities of records that look up to one parent. To see if you have data skew, look for counts of 6,000 or more in this query. Run this multiple times, replacing lookup_field_n for each lookup or master-detail relationship field that is prone to locking:

SELECT lookup_field_n, COUNT(*) AS count
FROM table_name
GROUP BY lookup_field_n
ORDER BY count(*) DESC

Parameters​

NameTypeDefaultDescription
@sObjectNVARCHARRequiredSalesforce object name to load data into
@tableNVARCHARRequiredInput SQL table containing data to load
@operationNVARCHARRequiredOperation type ('insert', 'update', 'upsert', 'delete', 'hardDelete')
@foreign_keysNVARCHARRequiredComma-separated list of foreign key column names to analyze for dependencies. Can accept a list of 1, 2 or even more ids (2 is most common). See recommended recipes below
@batch_sizeINTNULLMaximum batch size for processing. Note that LockBuster may create batches lower than this size
@externalIdNVARCHARNULLExternal ID field name (required for upsert operations)
@dry_runBIT0When set to 1, validates field mapping and reports results without sending any data to Salesforce. See Dry Run

In general, passing references to grandparent/great-grandparent objects is more conservative and more likely to lead to success than passing a parent object. For example, when loading OpportunityLineItems for a standard Salesforce org, passing the Product Id and Opportunity Id references succeeds. However, if the org has been customized with Opportunity roll-up summaries on the Account, then locking at the Account (grandparent object) could still occur because locks have only been prevented at the Opportunity (parent object) level. Passing the Account Id (grandparent) reference instead of the Opportunity Id (parent) reference fixes this.

The references passed to @foreign_keys do not need to be actual Salesforce fields or even Salesforce Ids. They can be external ids or other identifiers that describe the relationship of the current object to its predecessors.

Junction Object Recipe​

Set @foreign_keys to

  • The two lookup/master-detail lookup fields

Example:

EXEC dbo.SLAM_load_lockbuster
@sObject = 'Junction_Object__c',
@table = 'Junction_Object__c_insert',
@operation = 'insert',
@foreign_keys = 'Lookup_Field_1__c,Lookup_Field_2__c';

QuoteLineItem / SBQQ__QuoteLine__c Recipe​

Set @foreign_keys to

  • Product2Id
  • QuoteId
  • QuoteLineGroupId (if groups in use)

Example:

EXEC dbo.SLAM_load_lockbuster
@sObject = 'QuoteLineItem',
@table = 'QuoteLineItem_insert',
@operation = 'insert',
@foreign_keys = 'Product2Id,QuoteId,QuoteLineGroupId';

OpportunityLineItem Recipe​

Set @foreign_keys to

  • Product2Id
  • OpportunityId (*)
  • Pricebook2Id (if multiple pricebooks in use)
  • Campaign Ultimate Parent Id (**) (if Opportunity Campaigns in use)
Footnotes

(*) If there are rollup summaries from Opportunities onto Accounts, replace the OpportunityId with the AccountId

(**) CampaignId can be used instead of Campaign Ultimate Parent Id if it is permissible to temporarily flatten the Campaign hierarchy (by blanking out the ParentId). The built-in rollup summary in the Campaign hierarchy is prone to causing lock contention due to native Salesforce processing up the hierarchy

Example:

EXEC dbo.SLAM_load_lockbuster
@sObject = 'OpportunityLineItem',
@table = 'OpportunityLineItem_insert',
@operation = 'insert',
@foreign_keys = 'Product2Id,OpportunityId,Pricebook2Id';

CampaignMember Recipe​

Set @foreign_keys to

  • Campaign Ultimate Parent Id (*)
  • ContactId (if Contacts in use)
  • LeadId (if Leads in use)
  • AccountId (if Accounts in use)
Footnotes

(*) CampaignId can be used instead of Campaign Ultimate Parent Id if it is permissible to temporarily flatten the Campaign hierarchy (by blanking out the ParentId). The built-in rollup summary in the Campaign hierarchy is prone to causing lock contention due to native Salesforce processing up the hierarchy

Usage Examples​

Load CampaignMember records (assuming flat hierarchy):

EXEC dbo.SLAM_load_lockbuster
@sObject = 'CampaignMember',
@table = 'CampaignMember_insert',
@operation = 'insert',
@foreign_keys = 'ContactId,CampaignId';

Load CampaignMember records (assuming nested hierarchy):

-- Add the Ultimate_Parent_Id column
ALTER TABLE CampaignMember_insert ADD Ultimate_Parent_Id NVARCHAR(18);
GO

-- Campaign_replicated holds the Campaign records, for example from SLAM_replicate
WITH CampaignHierarchy AS (
SELECT Id AS CampaignId, Id, ParentId
FROM Campaign_replicated
UNION ALL
SELECT ch.CampaignId, p.Id, p.ParentId
FROM CampaignHierarchy ch
INNER JOIN Campaign_replicated p ON p.Id = ch.ParentId
),
UltimateParents AS (
-- The ultimate parent of each campaign is its ancestor with no parent
SELECT
CampaignId,
Id AS Ultimate_Parent_Id
FROM CampaignHierarchy
WHERE ParentId IS NULL
)
UPDATE cm
SET cm.Ultimate_Parent_Id = up.Ultimate_Parent_Id
FROM CampaignMember_insert cm
INNER JOIN UltimateParents up ON up.CampaignId = cm.CampaignId;

-- load
EXEC dbo.SLAM_load_lockbuster
@sObject = 'CampaignMember',
@table = 'CampaignMember_insert',
@operation = 'insert',
@foreign_keys = 'ContactId,Ultimate_Parent_Id';

Upsert QuoteLineItem records and create relationships on external ids:

EXEC dbo.SLAM_load_lockbuster
@sObject = 'QuoteLineItem',
@table = 'QuoteLineItem_upsert',
@operation = 'upsert',
@foreign_keys = 'Product2.External_Product2_Id__c,QuoteId.External_Quote_Id__c',
@batch_size = 10000,
@externalId = 'External_QuoteLineItem_Id__c';

Delete OpportunityLineItem records:

EXEC dbo.SLAM_load_lockbuster
@sObject = 'OpportunityLineItem',
@table = 'OpportunityLineItem_delete',
@operation = 'delete',
@foreign_keys = 'OpportunityId,Product2Id',
@batch_size = 10000;