Skip to content

Salesforce Pilots FORMULA() in SOQL WHERE Clauses

Summer '26 SOQL FORMULA() in WHERE pilot with an order profit filter example

SOQL has always been good at filtering on stored field values, but less helpful when the condition itself is a calculation. Profit is revenue minus cost. Shipping delay is ship date minus order date. Until now, filtering on those results usually meant adding a formula field or retrieving a wider set of records and calculating the answer in Apex.

Salesforce is testing a different approach in Summer ‘26. FORMULA() in SOQL is a pilot function that places a quoted arithmetic expression inside a WHERE comparison, allowing the platform to filter on the calculated result.

That is an interesting direction for SOQL, particularly for query-specific rules and packaged applications that cannot freely change a subscriber’s schema. It is also early. The public contract is currently limited to a Summer ‘26 release note and a Salesforce Enterprise API team announcement, so this post focuses on what Salesforce has actually documented and what still needs testing.

The useful part of this pilot is its query-specific placement: the calculation stays with the query that needs it. Salesforce describes the expression as being evaluated as part of filtering, so callers can receive records that already satisfy the calculated condition.

The published syntax is:

WHERE FORMULA('<arithmetic expression>') <comparison operator> <literal>

Salesforce currently documents addition and subtraction (+ and -) with these result types:

Result typePublished pilot behaviour
DOUBLESupported as a numeric result
INTEGERTreated like DOUBLE
CURRENCYSupported as a currency result
DATETIMESupported for date/time arithmetic
DATETreated like DATETIME

The official examples demonstrate > and <= comparisons and combine a computed condition with an ordinary field filter using AND.

When a filter depends on a calculated value, the established options each carry a trade-off:

  • Create a formula field: reusable and dependable, but unnecessary metadata if only one query needs the result.
  • Filter in Apex: flexible, but the query retrieves records that code may immediately discard.
  • Filter downstream: moves the calculation to an integration or analytics process and transfers a wider dataset.

FORMULA() targets cases where the calculation belongs only to data retrieval. It could reduce one-off fields, keep filter logic visible in code review, and remove some post-query loops. This is particularly relevant for ISVs and integration developers working with schemas they do not control.

Salesforce’s announcement uses an e-commerce order scenario. A custom object named Order__c can collide with Salesforce’s standard Order object, so this version uses the deliberately test-specific API name Formula_Test_Order__c.

Add these custom fields:

FieldTypePurpose
Revenue__cCurrencyTotal order value
Cost__cCurrencyFulfilment cost
OrderDate__cDateDate the customer placed the order
ShipDate__cDateDate the order shipped
Status__cTextCurrent order status

Then create the seven records used by the published examples:

OrderRevenueCostOrderDateShipDateStatus
ORD-00150020001 Apr02 AprShipped
ORD-00240025005 Apr12 AprShipped
ORD-00380030010 Apr11 AprShipped
ORD-00430015012 Apr14 AprDelivered
ORD-005120040015 Apr25 AprShipped
ORD-00655042018 Apr20 AprDelivered
ORD-00765045020 Apr21 AprShipped

These records assume one currency, populated input fields, and date-only values. Nulls, multiple currencies, and DateTime boundaries belong in a separate edge-case test.

To find shipped orders with profit greater than 250:

SELECT Id, Name, Revenue__c, Cost__c
FROM Formula_Test_Order__c
WHERE Status__c = 'Shipped'
AND FORMULA('Revenue__c - Cost__c') > 250

Against the sample data, this returns ORD-001, ORD-003, and ORD-005. Without the pilot, the same rule needs a formula field or a calculation after querying candidate records.

To find orders that shipped more than three days after the order date:

SELECT Id, Name, OrderDate__c, ShipDate__c
FROM Formula_Test_Order__c
WHERE FORMULA('ShipDate__c - OrderDate__c') > 3

This returns ORD-002 and ORD-005. Salesforce uses the comparison to represent days, but has not documented fractional-day, time-zone, or daylight-saving behaviour for DateTime subtraction.

🔗 Combine Computed and Standard Conditions

Section titled “🔗 Combine Computed and Standard Conditions”

To find orders with revenue above 600 that shipped within two days:

SELECT Id, Name, Revenue__c, OrderDate__c, ShipDate__c
FROM Formula_Test_Order__c
WHERE Revenue__c > 600
AND FORMULA('ShipDate__c - OrderDate__c') <= 2

This returns ORD-003 and ORD-007, demonstrating that the computed condition can sit beside an ordinary filter.

The feature is not a replacement for formula fields. The important design question is whether the calculated value belongs in the data model or only in one query.

ApproachBest fitWatch for
Formula fieldThe value is reused in reports, list views, page layouts, validation, or automation.Adds metadata and becomes a maintained business definition.
FORMULA() in WHEREThe arithmetic is query-specific, fits the documented pilot scope, and the org is enrolled.Pilot change risk and undocumented edge cases.
Apex or downstream filteringThe rule requires richer logic or the pilot is unavailable.More records may cross the query boundary.

For durable SOQL design, the existing guides on filtering with WHERE, advanced filter logic, and query performance remain the stable foundation.

⚠️ What the Public Material Does Not Yet Answer

Section titled “⚠️ What the Public Material Does Not Yet Answer”

As at 24 July 2026, Salesforce has published enough to try the feature, but not enough to treat every formula-field assumption as valid in SOQL:

AreaPublishedStill needs pilot testing
PlacementWHERE only, not HAVINGOther clauses and tooling support
ArithmeticAddition and subtractionFunctions, multiplication, division, and nested complexity
Result typesDOUBLE, INTEGER, CURRENCY, DATE, DATETIMENull propagation and mixed-type coercion
DatesDATE behaves like DATETIME; the example subtracts dates as daysFractional days, time zones, daylight saving, and precision
CurrencyCurrency expressions are supportedMulti-currency conversion and rounding
Query operationsApex and API callers can receive filtered rowsBind variables inside expressions, relationship references, indexing, and Query Plan behaviour

Treat anything in the right-hand column as a test question, not a platform promise. Recheck the release note and developer announcement after every Salesforce release.

💭 My Take: Promising, with Potential to Expand

Section titled “💭 My Take: Promising, with Potential to Expand”

My view is that FORMULA() is a genuinely useful and potentially very exciting addition to SOQL. Keeping a small, query-specific calculation inside WHERE solves a real problem: it can avoid creating a formula field solely to support one query, or retrieving rows only to discard them in Apex.

The pilot already addresses useful cases, but I would not redesign an established production solution around it yet. That caution comes from its pilot status, undocumented query-planning behaviour, and the open questions above, not from a lack of value in what it can do today.

If Salesforce expands the feature in future, one possibility could be returning a calculated value from SELECT, such as a profit or age value alongside the underlying fields. This might reduce repeated calculations in Apex and API consumers without requiring every temporary value to become part of the object schema. Salesforce has not announced this capability, but it is an interesting direction the feature could take.

The goal of a pilot test is to produce evidence that can survive a release change, rather than a single successful query in Developer Console.

  1. Request enrolment and confirm the pilot terms with your Salesforce contact.

  2. Reproduce the published examples in a non-production org before extending the syntax.

  3. Add edge cases for nulls, negative values, mixed numeric types, multiple currencies, and DateTime boundaries.

  4. Test realistic volume and compare Query Plans, timings, and returned-row counts with the existing implementation.

  5. Use the real execution context so record and field access match the eventual Apex or API caller.

  6. Document the environment and exact query when sharing feedback in the Salesforce Developers Trailblazer Community.

Keep the expression static rather than building it from user-controlled input. If dynamic SOQL is unavoidable, apply the usual injection controls and retain the security practices used for any SOQL query.


I think FORMULA() has a genuine place in SOQL: small, query-local calculations that do not deserve permanent metadata. The pilot already demonstrates that value, and I am interested to see how Salesforce expands the idea.

It will be interesting to see whether the feature eventually grows to include calculated values in SELECT, but that possibility should not be confused with the published pilot. For now, this is a feature to evaluate, not a settled SOQL pattern. Keep production designs on documented capabilities and treat pilot results as provisional evidence.