https://github.com/jpmonette/q
A Dynamic SOQL Query Builder for the Force.com Platform ☁️
https://github.com/jpmonette/q
apex salesforce sfdx soql sosl
Last synced: 5 months ago
JSON representation
A Dynamic SOQL Query Builder for the Force.com Platform ☁️
- Host: GitHub
- URL: https://github.com/jpmonette/q
- Owner: jpmonette
- License: mit
- Created: 2017-03-30T10:31:05.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2020-05-07T19:20:28.000Z (about 6 years ago)
- Last Synced: 2025-06-02T11:59:22.444Z (about 1 year ago)
- Topics: apex, salesforce, sfdx, soql, sosl
- Language: Apex
- Homepage:
- Size: 17.1 MB
- Stars: 49
- Watchers: 6
- Forks: 25
- Open Issues: 12
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Project Q
A Dynamic [SOQL Query](https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_sosl_intro.htm) Builder for the [Force.com Platform](https://developer.salesforce.com/docs/atlas.en-us.fundamentals.meta/fundamentals/adg_preface.htm)
[](https://travis-ci.org/jpmonette/q)
[](https://coveralls.io/github/jpmonette/q?branch=master)
## Installation
Deploy the Apex classes from the `./force-app/main/default/classes/` repository into your Salesforce project.
## Usage
```java
Q query = new Q(Account.SObjectType)
.selectFields(SObjectType.Account.fieldSets.Example)
.addSubquery(new Q('Contacts'))
.add(Q.condition('Name').isLike('%Acme%'))
.add(Q.condition('BillingCountry').isNotNull())
.addLimit(5);
System.debug(query.build());
// SELECT CreatedById, Description, Owner.Email, (SELECT Id FROM Contacts) FROM Account WHERE Name LIKE '%Acme%' AND BillingCountry != null LIMIT 5
```
While chaining methods is a convenient way to initialise your query, you also have the ability to manually build complex queries depending on specific conditions.
```java
Q query = new Q(Contact.SObjectType).addLimit(5);
if (String.isNotBlank(firstName)) {
query.add(Q.condition('FirstName').equalsTo(firstName))
}
if (String.isNotBlank(lastName)) {
query.add(Q.condition('LastName').equalsTo(lastName))
}
System.debug(query.build());
// SELECT Id FROM Contact WHERE FirstName = 'Céline' AND LastName = 'Dion' LIMIT 5
```
## Roadmap
This library is being initially developed for one of my internal project,
so API methods will likely be implemented in the order that they are
needed by my project. Eventually, I would like to cover the entire
SOQL and SOSL query language, so contributions are of course
[always welcome][contributing]. Adding new methods is relatively
straightforward, so feel free to join the fun!
[contributing]: CONTRIBUTING.md
## License
This library is distributed under the MIT license found in the [LICENSE](./LICENSE)
file.