SOQL Language Support
Overview
SOQL is Salesforce's version of SQL. It largely uses standard SQL syntax but with some important distinctions. This page describes some of those differences, but for a more detailed description of SOQL syntax and function, refer to the Salesforce documentation.
Use the query operations to retrieve records from a single object. When an sObject entity name is provided instead of a query, the operation runs SELECT * FROM <sObject>. All operations are logged to SLAM_Activity_Log.
Speediful automatically parses and expands certain query syntax:
SELECT * FROM <sObject>(Selects all fields from the object)SELECT FIELDS(CUSTOM) FROM <sObject>(Selects all custom fields from the object)SELECT FIELDS(STANDARD) FROM <sObject>(Selects all standard fields from the object)SELECT FIELDS(ALL) FROM <sObject>(Selects all fields from the object)
This parsing means that you can perform a SELECT FIELDS(...) operation without having to specify a LIMIT clause as would otherwise be required by SOQL
Relationship fields are supported by all APIs, to any depth Salesforce itself allows
(currently 5 levels from the root object) e.g.
SELECT Account.Name, Account.Type, FirstName, LastName, Email, Owner.Name FROM Contact,
or a deeper path such as Account.Owner.Manager.Manager.Name. Salesforce rejects a path
beyond its own limit with a clear error naming the limit; Speediful does not impose a
separate, lower limit of its own.
A polymorphic relationship field (one that can point at more than one kind of
object, such as Owner, What, or Who) can only be followed by fields of the related
record's Name entity, for example Owner.Name or What.Owner.Name. Salesforce itself
restricts what is queryable through this kind of relationship; query the related object
directly and join the results in SQL Server for anything else.
Some examples of SOQL queries you can pass
-
LIKE filtering:
@query = 'SELECT * FROM Account WHERE Name LIKE ''%United Oil%''' -
Date filtering:
@query = 'SELECT * FROM Account WHERE CreatedDate > 2025-08-01T01:02:03Z' -
Date function filtering:
@query = 'SELECT * FROM Account WHERE LastModifiedDate > N_DAYS_AGO:20' -
Relationship fields:
@query = 'SELECT Id, Owner.Name, FIELDS(CUSTOM) FROM Account LIMIT 1000'
A query can span several lines, the way you would lay it out in SSMS:
EXEC dbo.SLAM_query
@query = 'SELECT Id, Name, Industry
FROM Account
WHERE Industry = ''Energy''',
@table = 'Account_Energy',
@api = 'bulk'
Speediful sends each line break as a space, which SOQL treats the same as a line break
between keywords and field names. A line break inside a quoted value is also sent as a
space, so keep each quoted value in the WHERE clause on one line.
Deleted and archived records (which in particular, applies to Task and Event objects), can be retrieved by passing parameter @queryAll = 1 to the query procedure.
Text in a SOQL query must be representable in the database's code page (for example, accented Latin letters in a Latin1 database). A query containing other characters, such as Chinese or Cyrillic text in a Latin1 database, is not run: the procedure reports error 88318 rather than sending an altered query to Salesforce. Filter on those values in SQL Server after querying instead.
Wide Salesforce Tables
A Salesforce object can have its standard fields plus up to 800 custom fields, so a
SELECT * query on a wide object can exceed the 10,000 character SOQL limit. Speediful splits it into several queries
over different fields of the same records, then joins their results into one destination
table with every column requested.
Before the join, Speediful prints:
Combining the results of N queries over different fields of the same records into <table>.
When the join ends, it prints:
Finished combining the results into <table> (<elapsed time>).
The join can take minutes on a large result, so the first line tells you the run is working, not stalled.
The joined table must still fit in one SQL Server table, which can have at most 1,024
columns and 8,060 bytes in a row. A query that selects more stops with error 88322. If the
join fails, nothing is written to the destination table. Speediful keeps the downloaded
records in the tables it joins from (<table>_vshard_0, <table>_vshard_1, and so on) and
names them in the Results pane. See Query Results Too Wide.
The command that SQL Server sends to Speediful is limited to 8,000 characters, so a SOQL
query passed to a stored procedure must fit within that limit together with the connection
details. A query that is too long is not run: the procedure reports error 88317, stating
how long the query is. Use SELECT * or FIELDS() rather than listing many fields
explicitly.
Field Functions
Speediful resolves three Salesforce field-wrapping functions in a query's select list,
each optionally aliased: toLabel(field), FORMAT(field), and convertCurrency(field).
The result column is named after the field it wraps, or after the alias if you give one,
never after the function-call text. It keeps the relationship prefix of a wrapped
relationship field: toLabel(Account.Industry) produces a column named
Account.Industry, and toLabel(Account.Industry) Ind produces Account.Ind.
toLabel(field)returns the picklist label text for the field's current value (localized to the running user), stored as text sized to the field's own definition.FORMAT(field)returns the value rendered in the running user's locale (currency, date, percent and so on, as locale-formatted text such as$500,000.00), always as text regardless of the wrapped field's own type.convertCurrency(field)returns the value converted to the running user's currency, keeping the wrapped field's own numeric type. On a single-currency org Salesforce itself rejects it withcurrency conversion not supported in this organization.
Selecting the same field both raw and wrapped with no alias (StageName, toLabel(StageName)) is rejected by Salesforce as a duplicate column; add an alias to
one of them. All three functions are supported on the SOAP, Bulk v1, and Bulk v2 APIs.
SLAM_download_job (re-downloading an
already-submitted Bulk v2 query job's results by job id, without re-running the
query) cannot recover which columns of that job used one of these functions, since
Salesforce's job-status endpoint does not return the original query text. It types
every column from the field it is named after instead. A column that used FORMAT or
toLabel can therefore come back incorrectly converted (for example a locale-formatted
FORMAT(Amount) value forced through Amount's own numeric conversion). Re-run the
query through SLAM_query_bulkv2 instead of downloading by job id if it used
toLabel, FORMAT, or convertCurrency.
Unresolvable Fields
If a field you name in a query (including a relationship field, e.g. Owner.Name) cannot be resolved against the object's schema, the operation fails with an error naming that field, instead of silently omitting it from the result. If you see this error on a query that previously appeared to work, check the field name for typos, and confirm it isn't deleted or hidden from your user by field-level security.
A query also fails when two fields in it would produce the same column name, for example
SELECT toLabel(StageName) Stage, toLabel(Type) Stage FROM Opportunity. The error names
both fields. Give one of them a different alias.
SOAP Query Limitations
Aggregate queries via the SOAP API are not supported at this time e.g. SELECT Type, SUM(AnnualRevenue) FROM Account
Subqueries are not supported e.g. SELECT Name, Type, (SELECT FirstName, LastName, Email FROM Contact) FROM Account
In both of these cases you will be better served copying the required sObject records to the database and performing the equivalent SQL query.