SLAM_query_bulk
Overview
This command uses the Salesforce Bulk v1 API to query the object. If an sObject name is provided instead of a SOQL query, all fields and records are returned for that object.
Performance tip: Some Salesforce objects support PK Chunking, which parallelizes the query operation on the Salesforce server. This can make queries much faster. To enable PK Chunking, provide a value for @pkchunksize (typical values are 100,000 up to a max of 250,000). Refer to Salesforce Bulk Documentation for more details including the list of objects that are supported. Salesforce supports PK Chunking a SOQL query that already has filter criteria.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
@query | NVARCHAR | Required | sObject name or SOQL query string. When just an sObject name is passed, queries all records & fields |
@table | VARCHAR | Required | Target SQL table name for results |
@pkchunksize | INT | NULL | Enables PK chunking for large datasets when specified. If NULL, no chunking. Typical values: 100,000 to max of 250,000. Use a smaller value for an object with many fields; Speediful warns when each chunk is large for the query and never changes the value. See Choosing a chunk size |
@queryall | BIT | 0 | When 1, includes deleted/archived records |
@exists_action | VARCHAR(20) | NULL | Controls the behavior when the destination table name, specified by @table is already used. If NULL, uses the value from SLAM_Settings.default_exists_action (defaulted to 'drop' during initial setup).Valid options:
|
Choosing a chunk size
SLAM_query_bulk uses PK chunking only when you set @pkchunksize. SLAM_replicate uses a
chunk size of 100,000 by default. The maximum size is 250,000. Smaller chunk sizes result in
more batches on the Salesforce server, which usually results in faster processing time, but
each batch counts toward the platform's limit. 100,000 is usually a good starting point.
Memory use on wide objects
Wide objects (many fields, or long text fields with a lot of text) can produce large result
files, with or without PK chunking. One file can take a large share of the memory
configured for Speediful, or more. The first large files can briefly use more memory than
the limit allows; after that, Speediful downloads fewer files at a time so that memory stays
within its limits. With PK chunking on, Speediful prints a warning when a chunk is large,
and a smaller @pkchunksize makes each file smaller. Speediful never changes
@pkchunksize. To increase the memory for Speediful, see
Resource Governance.
WARNING: @pkchunksize = 100,000 is large for this query of Account relative to the memory
reserved by Speediful. Therefore, processing of Salesforce query results will be throttled
by Speediful. Observed chunk size of 481 MB vs reserved 205 MB. The query continues with
your value, but memory usage will initially spike, and subsequent batches will download
fewer at a time. Consider increasing the memory limit for Speediful or using a smaller
@pkchunksize value.
The warning is one line in the Messages output; it is wrapped here to fit the page.
Usage Examples
Retrieve all records and fields from the Account object:
EXEC dbo.SLAM_query_bulk
@query = 'Account',
@table = 'Account_query';
Retrieve a filtered set of records from the Account object:
EXEC dbo.SLAM_query_bulk
@query = 'SELECT * FROM Account WHERE CreatedDate > 2025-08-01T01:02:03Z',
@table = 'Account_query';
Retrieve deleted and archived records with PK Chunking:
EXEC dbo.SLAM_query_bulk
@query = 'SELECT Id, IsDeleted, Subject, Status, OwnerId FROM Task',
@table = 'Task_queryall',
@pkchunksize = 100000,
@queryall = 1;