Skip to content

Distance Function#273

Draft
stackasaur wants to merge 3 commits intobeyond-the-cloud-dev:release/v6.9.0from
stackasaur:feature/distance
Draft

Distance Function#273
stackasaur wants to merge 3 commits intobeyond-the-cloud-dev:release/v6.9.0from
stackasaur:feature/distance

Conversation

@stackasaur
Copy link
Contributor

@stackasaur stackasaur commented Feb 19, 2026

Description

Type of Change

  • New feature (non-breaking change which adds functionality)

Changes Made

  • Added Distance interface
  • Added SoqlDistance class implementing Distance interface
  • Added distance as a valid argument for:
    • Filter.with(Distance distance)
    • orderby(Distance distance) in both Queryable and SubQuery
  • Added internal variable for QueryBy and SoqlFilter to hold distance or String and modified the toString methods to use Distance when supplied.

Related Issues

Fixes #271

Testing

  • All existing tests pass (npm test)
  • Added new tests for new functionality
  • Tested in scratch org
  • Linting passes (npm run lint)
  • Code formatting is correct (npm run prettier:verify)

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code where necessary
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings or errors
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published

Additional Notes

Example:

// distance could also be declared inline
Soql.Distance dist = SOQL.distance.of(Account.BillingAddress)
  .between(72.0,-136.0)
  .mi();

System.debug(
  SOQL.of(Account.sObjectType)
  .whereAre(
    SOQL.filter.with(dist.lessThan(5))
  .orderBy(dist)
  .toString()             
);

// outputs: 
// SELECT Id FROM Account WHERE DISTANCE(BillingAddress,:v1,'mi') < :v2 ORDER BY DISTANCE(BillingAddress,:v3,'mi') ASC NULLS FIRST

@vercel
Copy link

vercel bot commented Feb 19, 2026

@stackasaur is attempting to deploy a commit to the Beyond The Cloud Team on Vercel.

A member of the Team first needs to authorize it.

Distance mi();
Distance km();
}

Copy link
Contributor Author

@stackasaur stackasaur Feb 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the SOQL docs describe how a call to geolocation must be the second arg of distance, but they're a bit ambigous on what you CAN do.

I couldn't get any permutation of arguments to work other than:
DISTANCE(field, geolocation, unit).

this doesn't work and wouldn't make much sense:
DISTANCE(geolocation, geolocation, unit)

and this didn't compile even though it DOES make sense:
DISTANCE(field, field, unit)

@pgajek2 pgajek2 changed the base branch from main to release/v6.9.0 March 2, 2026 20:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Need DISTANCE Function

1 participant