← Back to Pull requests

fix(salesforce): add Id and LastModifiedDate to SOQL rules unless they are selected #4880

Open
unknown opened this pull request with 507 lines diff across 6 files
View on GitHub
unknown unknown commented on Nov 01, 2026 12:32 UTC
Author

Relates to: no issue

This is a bug I found while reading the Salesforce client.

Before running a SOQL advanced sync rule, SalesforceClient adds Id and LastModifiedDate to the SELECT clause, because SalesforceDocMapper.map_salesforce_objects builds _id, url and _timestamp from them. Both helpers decide whether the field is already selected by searching the whole query:

  • _add_last_modified_date checks "lastmodifieddate" not in query.lower()

  • _add_id checks re.search(r"\bid\b", query.lower())
  • So the field is skipped when it only appears outside the select list, or inside another field name. Some rules this affects, on main:

    | Rule query | Query sent to Salesforce |
    | --- | --- |
    | SELECT Id, Name FROM Account WHERE LastModifiedDate > LAST_N_DAYS:7 | unchanged, no LastModifiedDate selected |
    | SELECT Id, LastModifiedDate__c FROM Account | unchanged, no LastModifiedDate selected |
    | SELECT Name, Owner.Id FROM Account | SELECT Name, Owner.Id, LastModifiedDate FROM Account, no Id selected |
    | SELECT Name, (SELECT Id FROM Contacts) FROM Account | no Id selected |
    | SELECT Name FROM Account WHERE Id IN (SELECT AccountId FROM Contact) | no Id selected |

    Salesforce only returns the fields that are selected, so for these rules every document gets _id: None and a url ending in /None, or a _timestamp set to the sync time instead of the record's last modification. With a sync-time _timestamp, unchanged records are never skipped on later syncs.

    The fix adds a small _split_select_clause helper that walks the outer SELECT list, skipping commas and FROM inside parentheses (subqueries and functions), and returns the top-level fields and the position of the outer FROM. _add_id and _add_last_modified_date now share _add_selected_field, which adds the field only when it is not one of those top-level fields (case-insensitive, as SOQL field names are), and inserts it before the outer FROM. Inserting there also stops the field from landing in a WHERE ... IN (SELECT ... FROM ...) subquery, which the old greedy SELECT (.*) FROM substitution did. The FIELDS(ALL) / FIELDS(STANDARD) checks are unchanged.

    Checklists

    Pre-Review Checklist


  • this PR does NOT contain credentials of any kind, such as API keys or username/passwords (double check config.yml.example)

  • this PR has a meaningful title

  • this PR links to all relevant github issues that it fixes or partially addresses

  • this PR has a thorough description

  • Covered the changes with automated tests

  • Tested the changes locally

  • Added a label for each target release version (example: v7.13.2, v7.14.0, v8.0.0)

  • Considered corresponding documentation changes

  • Contributed any configuration settings changes to the configuration reference

  • if you added or changed Rich Configurable Fields for a Native Connector, you made a corresponding PR in Kibana
  • Tests

    In tests/sources/test_salesforce.py, new cases for the existing parametrized tests:

  • test_add_last_modified_date: LastModifiedDate only in WHERE, a LastModifiedDate__c field, and Owner.LastModifiedDate now get LastModifiedDate added; a lowercase lastmodifieddate in the select list and FIELDS(ALL) are left as they are.

  • test_add_id: Owner.Id, an Id in a child subquery, and an Id only in a WHERE ... IN (SELECT ...) semi-join now get Id added before the outer FROM; a lowercase id in the select list is left as it is.
  • The 6 new add-the-field cases fail on main and pass with the fix. The rest of test_salesforce.py has the same results before and after the change (on my Windows machine, three content-document tests fail on main too because of the local base64 command). ruff check and ruff format --check are clean, apart from the repo-wide CPY001 notice.

    🤖 Generated with Claude Code

    Diff: 507 lines (+380 / -127) across 6 files Reviewer: ShivamSharma43 Review duration: 30729m
    All Vouch review confidence checks passed
    Residual risk 0.25 = Change Risk (0.48) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.48 · 507 lines diff across 6 files
    0.48
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.373
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #4880"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 47.6% (MEDIUM) · Higher = larger blast radius
    47.6%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 25.4% · Safe to merge
    25.4%