Skip to main content

SLAM_query_bulk

This command uses the Salesforce Bulk API to query the object. If no query is provided, all fields and records will be returned. The table is overwritten if it already exists.

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_actionAction to take if the target object name specified by @table is already taken. If NULL, uses the value from SLAM_Settings.default_exists_action (defaulted to 'drop' during initial setup).

Valid options:
  • 'drop'
  • 'rename'
  • 'fail'

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, Owner FROM Task',
@table = 'Task_queryall',
@pkchunksize = 100000,
@queryall = 1