Skip to main content

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 will be returned for that object.

Performance tip: Some Salesforce objects support PK Chunking, which parallelizes the query operation on the Salesforce server. This can lead to dramatic time reductions in query operations. 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

NameTypeDefaultDescription
@queryNVARCHARRequiredsObject name or SOQL query string. When just an sObject name is passed, queries all records & fields
@tableVARCHARRequiredTarget SQL table name for results
@pkchunksizeINTNULLEnables PK chunking for large datasets when specified. If NULL, no chunking. Typical values: 100,000 to max of 250,000
@queryallBIT0When 1, includes deleted/archived records
@exists_actionVARCHAR(20)SLAM_Settings.default_exists_actionControls 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:

  • 'drop' - Drop the existing object and create a new one (default)
  • 'rename' - Rename the existing object by appending a timestamp suffix (format: _YYYYMMDDTHHMMSS_MMM)
  • 'fail' - Throws a SQL exception if the destination object already exists

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;