SCALIX help

← All tools

salesforce_soql_query

Salesforce read low risk

Part of the Salesforce Agent.

What it does

Runs a read-only SOQL query against any Salesforce object the connected org/user can see (Lead, Contact, Account, Opportunity, Campaign, CampaignMember, or custom objects) and returns matching rows. Use to look up records before a write (e.g. find a Lead by email to avoid duplicates, resolve a Campaign Id by name, read Opportunity stage/amount, list CampaignMembers for attribution reporting). Key inputs: soql (the full SELECT statement); optional page_url (the nextRecordsUrl from a previous page) to continue pagination; all_rows to include soft-deleted/archived rows. Returns the JSON QueryResult: data.records[] (each with attributes.type + attributes.url + selected fields), data.totalSize (total matched, not just this page), data.done (false when more pages exist), and data.nextRecordsUrl (opaque locator for the next batch). Wrapper returns {success:true,data:{records,totalSize,done,nextRecordsUrl},count:records.length}. SELECT-only: any DML keyword (INSERT/UPDATE/DELETE/UPSERT/MERGE) or anonymous Apex is rejected client-side before the call. Always escape user-supplied literals (single-quote escaping) to prevent SOQL injection. Honors org field-level security and sharing rules — the connected user only sees what they are permitted to see. SOQL syntax: https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql.htm .

Inputs

NameTypeRequiredDescription
soqlstringyesA complete SELECT SOQL statement, e.g. "SELECT Id, Email, Company, Status FROM Lead WHERE Email = 'a@b.com' LIMIT 50". SELECT-only: a statement that does not start with SELECT (DML, anonymous Apex) is refused before the call. Escape single quotes in literals (' -> \') to block SOQL injection. Prefer an explicit LIMIT and ORDER BY for deterministic paging.
page_urlstringnoThe opaque nextRecordsUrl (e.g. /services/data/v67.0/query/01g...-2000) returned by a prior page when data.done was false. When set, soql is ignored and the next batch is fetched. Do not hand-construct this value.
all_rowsbooleannoWhen true, uses the queryAll resource to also return soft-deleted/archived rows (IsDeleted=true, archived Tasks/Events). Default false (queryAll is rarely needed for forwarding/attribution).

Safeguards

Policy

Read-only: SELECT statements only; never accept DML or anonymous Apex. Strict per-account isolation — query only within the org the bearer is scoped to; never join, pool, or compare records across different clients' orgs. Any LinkedIn member/lead data surfaced here may be used ONLY for the authorizing client and ONLY for consented purposes; never use query results to enrich, append, or verify member profiles, build a cross-account or prospecting/unaffiliated lead database, or commingle leads across clients. Do not retain member-derived rows beyond this request (member profile data <=24h, social activity <=48h); honor deletion on request; do not log returned PII.

Reminder

SELECT-only, escape all literals against SOQL injection, page via nextRecordsUrl, and never retain or cross-pool returned member/lead data.

Errors

Error classMeansWhat to doRetry
TOKEN_REVOKEDSession expired or invalid (HTTP 401, errorCode INVALID_SESSION_ID).needs_reauth — refresh the OAuth token once and retry the same read; if refresh fails, prompt the user to reconnect Salesforce.yes
PERMISSION_DENIEDUser lacks read access to the object/field, or the field is hidden by field-level security (HTTP 403 INSUFFICIENT_ACCESS / 400 INVALID_FIELD for an FLS-hidden field).Surface the exact object/field named; ask the admin to grant read access or remove the field from the SELECT. Do not retry unchanged.no
VALIDATION_ERRORMalformed SOQL (HTTP 400 MALFORMED_QUERY) or unknown object/field (INVALID_TYPE / INVALID_FIELD).Surface Salesforce's exact parser message (it includes the offending token/position); fix the SOQL and re-run. Do not guess field API names — verify via describe if unsure.no
NOT_FOUNDStale/expired query locator on pagination (HTTP 400 INVALID_QUERY_LOCATOR or 404).Re-run the original SOQL from page 1; query locators expire by age/row count. Do not reuse an old nextRecordsUrl.no
RATE_LIMITEDOrg 24h API request limit or concurrent-request limit exceeded (HTTP 403 REQUEST_LIMIT_EXCEEDED, or 503 with Retry-After).Backoff and honor Retry-After; report remaining quota from the Sforce-Limit-Info header. If the daily 24h limit is hit, surface that this is not retryable until reset.yes
PLATFORM_UNAVAILABLESalesforce 5xx or maintenance window (HTTP 500/502/503).Retry with exponential backoff (1/2/4s, cap 30s); reads are safe to retry. If persistent, report a transient Salesforce outage.yes

Edge cases

  • Empty result: data.records=[], totalSize=0, done=true — return success with count 0, not an error.
  • Pagination: REST caps a page at ~2000 rows (default 200 batch); when done=false, follow nextRecordsUrl until done=true. totalSize is the full match count across all pages.
  • Aggregate queries (COUNT(), GROUP BY) return synthetic rows with attributes.type='AggregateResult' and aliased fields (expr0...); handle absence of Id.
  • Relationship fields (Account.Name, Owner.Email) come back as nested objects, not flat keys.
  • Polymorphic fields (e.g. CampaignMember.Lead vs Contact) require care: only one of LeadId/ContactId is populated per row.
  • Retention/consent: results may contain LinkedIn-derived PII — treat as consent-scoped to this client, do not cache profile data beyond 24h or social activity beyond 48h, and never use it to build a cross-client dataset.