SLAM_replicate
Overview
SLAM_replicate copies several Salesforce objects in full to SQL Server in parallel. The objects specified in @sObjects are submitted to run in parallel with the Bulk v1 API. Each sObject is downloaded to a table named with @table_suffix (default "_replicated").
The command that SQL Server sends to Speediful is limited to 8,000 characters, including the connection details. If a long list of objects would exceed this limit, SLAM_replicate stops before running anything and reports error 88317, stating how long the object list is; split the list across multiple SLAM_replicate calls. Object names containing characters that the database's code page cannot represent are rejected with error 88318.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
@sObjects | NVARCHAR | Required | Comma-separated list of Salesforce object names to replicate |
@table_suffix | NVARCHAR | '_replicated' | Suffix to append to table names |
@pkchunksize | INT | 100000 | PK Chunksize to use for replication. Speediful disables PK Chunking for objects that do not support it. If NULL, PK Chunking is disabled. Speediful warns when an object's chunks are large for that object, and never changes the value. See Choosing a chunk size |
@queryall | BIT | 0 | When 1, includes deleted/archived records |
@max_workers | INT | 20 | Number of parallel processing threads. Lower this number if experiencing issues with job processing on Salesforce |
@exists_action | VARCHAR(20) | NULL | Controls the behavior when a destination table (each object's name followed by @table_suffix) already exists. With 'fail', the procedure checks every destination table first and fails before replicating anything if any of them exists. If NULL, uses the value from SLAM_Settings.default_exists_action (defaulted to 'drop' during initial setup).Valid options:
|
Reading the Messages Output
Because the sObjects are replicated in parallel, their progress messages arrive interleaved. Each message produced while replicating a specific sObject begins with that sObject's name in brackets, so the lines for one object can be picked out:
Starting concurrent replication of 2 objects with max 20 workers
[Account] Processed: 120,000
[Contact] Processed: 250,000
WARNING: [Contact] ...
OK: Account -> Account_replicated (API: bulk)
Messages about the run as a whole, such as the OK: line for each finished object and the final Replication Summary, have no prefix.
When Objects Fail
When one object fails, Speediful carries on with the others. A stalled write is the
exception: it stops the run, and Speediful starts no further objects. The Replication
Summary at the end lists each object that failed under Failed objects:, with its own
reason. The objects that finished keep their tables.
After the summary, the procedure raises one error for the whole run. When objects failed for different reasons, it raises the first of these that applies to any object:
| Order | Cause | Error |
|---|---|---|
| 1 | A write to SQL Server stopped making progress, so Speediful stopped the run | 88321 |
| 2 | SQL Server's transaction log is full | 88315 |
| 3 | SQL Server ran out of memory running BULK INSERT | 88314 |
| 4 | An object's results are too wide to store in one SQL Server table | 88322 |
| 5 | Any other failure | 88300 |
The first three come from SQL Server itself and can stop any object, so the procedure
reports them first. A result that is too wide comes from one object's fields and data.
Whichever error the procedure raises, the Failed objects: list gives every object's own
reason.
Usage Examples
Replicate multiple objects with default settings. This creates Account_replicated, Contact_replicated, Opportunity_replicated tables:
EXEC dbo.SLAM_replicate
@sObjects = 'Account,Contact,Opportunity';
Whitespace between items in the sObject list is ignored, so this is valid as well:
EXEC dbo.SLAM_replicate
@sObjects = 'Account
,Contact
,Opportunity';
Replicate with custom table suffix and batch size. This creates OpportunityLineItem_backup, WorkOrder_backup, WorkOrderLineItem_backup tables:
EXEC dbo.SLAM_replicate
@sObjects = 'OpportunityLineItem,WorkOrder,WorkOrderLineItem',
@table_suffix = '_backup',
@pkchunksize = 250000;
Full replication including deleted records with reduced parallelism:
EXEC dbo.SLAM_replicate
@sObjects = 'Case,CaseComment,FeedItem,Task,EmailMessage,Attachment,ContentVersion',
@table_suffix = '_full_backup',
@pkchunksize = 15000,
@queryall = 1,
@max_workers = 5;