Skip to content

Commit

Permalink
Btc 121 by record type (#89)
Browse files Browse the repository at this point in the history
* SOQL byRecordType

* byRecordType Test

* byRecordType documentation
  • Loading branch information
pgajek2 authored Oct 28, 2023
1 parent 562d118 commit 5b7a896
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
5 changes: 5 additions & 0 deletions force-app/main/default/classes/SOQL.cls
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ public virtual inherited sharing class SOQL implements Queryable {
// DEBUGGING
Queryable preview();
// PREDEFINIED
Queryable byRecordType(String recordTypeDeveloperName);
Queryable byId(SObject record);
Queryable byId(Id recordId);
Queryable byIds(Iterable<Id> recordIds);
Expand Down Expand Up @@ -605,6 +606,10 @@ public virtual inherited sharing class SOQL implements Queryable {
return executor.toQueryLocator();
}

public SOQL byRecordType(String rtDeveloperName) {
return whereAre(Filter.recordType().equal(rtDeveloperName));
}

public SOQL byId(SObject record) {
return byId(record.Id);
}
Expand Down
13 changes: 13 additions & 0 deletions force-app/main/default/classes/SOQL_Test.cls
Original file line number Diff line number Diff line change
Expand Up @@ -1502,6 +1502,19 @@ private class SOQL_Test {
Assert.areEqual('SELECT Id FROM Account ALL ROWS', soql);
}

@IsTest
static void byRecordType() {
// Test
SOQL builder = SOQL.of(Case.SObjectType).byRecordType('CaseRecordType');

// Verify
String soql = builder.toString();
Assert.areEqual('SELECT Id FROM Case WHERE RecordType.DeveloperName = :v1', soql);

Map<String, Object> binding = builder.binding();
Assert.areEqual('CaseRecordType', binding.get('v1'));
}

@IsTest
static void byId() {
// Test
Expand Down
22 changes: 22 additions & 0 deletions website/docs/api/soql.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ The following are methods for `SOQL`.

[**PREDEFINIED**](#predefinied)

- [`byRecordType(String recordTypeDeveloperName)`](#byrecordtype)
- [`byId(SObject record)`](#byid)
- [`byId(Id recordId)`](#byid)
- [`byIds(Iterable<Id> recordIds)`](#byids)
Expand Down Expand Up @@ -1274,6 +1275,27 @@ WHERE ((Id = :v1 OR Name LIKE :v2))
For all predefined methods SOQL instance is returned so you can still adjust query before execution.
Add additional fields with [`.with`](#select).

### byRecordType

**Signature**

```apex
SOQL byRecordType(String recordTypeDeveloperName)
```

**Example**

```sql
SELECT Id
FROM Case
WHERE RecordType.DeveloperName = 'CaseRecordType'
```
```apex
SOQL.of(Case.SObjectType)
.byRecordType('CaseRecordType')
.toList();
```

### byId

**Signature**
Expand Down

0 comments on commit 5b7a896

Please sign in to comment.