Skip to main content

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​

NameTypeDefaultDescription
@sObjectsNVARCHARRequiredComma-separated list of Salesforce object names to replicate
@table_suffixNVARCHAR'_replicated'Suffix to append to table names
@pkchunksizeINT100000PK 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
@queryallBIT0When 1, includes deleted/archived records
@max_workersINT20Number of parallel processing threads. Lower this number if experiencing issues with job processing on Salesforce
@exists_actionVARCHAR(20)NULLControls 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:

  • 'drop' - Drop the existing object and create a new one (default)
  • 'rename' - Rename the existing object by appending a timestamp suffix (format: _YYYYMMDDTHHMMSS_MMM)
  • 'append' - Add the rows to the existing table and keep the rows already in it. See Appending to an existing table
  • 'fail' - Throws a SQL exception if the destination object already exists
  • 'drop-after' - Like 'drop', but keeps the existing object, renamed, until the run succeeds. See The drop-after option

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:

OrderCauseError
1A write to SQL Server stopped making progress, so Speediful stopped the run88321
2SQL Server's transaction log is full88315
3SQL Server ran out of memory running BULK INSERT88314
4An object's results are too wide to store in one SQL Server table88322
5Any other failure88300

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;