Skip to content

Commit 89697e1

Browse files
committed
documentation update
1 parent 0692e52 commit 89697e1

File tree

2 files changed

+179
-1
lines changed

2 files changed

+179
-1
lines changed

website/docs/soql/api/soql.md

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@ The following are methods for using `SOQL`:
206206
- [`toAggregatedMap(SObjectField keyField)`](#toaggregatedmap)
207207
- [`toAggregatedMap(String relationshipName, SObjectField targetKeyField)`](#toaggregatedmap-with-custom-relationship-key)
208208
- [`toAggregatedMap(SObjectField keyField, SObjectField valueField)`](#toaggregatedmap-with-custom-value)
209+
- [`toIdMapBy(SObjectField field)`](#toidmapby)
210+
- [`toIdMapBy(String relationshipName, SObjectField targetKeyField)`](#toidmapby-with-relationship)
211+
- [`toAggregatedIdMapBy(SObjectField keyField)`](#toaggregateidmapby)
212+
- [`toAggregatedIdMapBy(String relationshipName, SObjectField targetKeyField)`](#toaggregateidmapby-with-relationship)
209213
- [`toQueryLocator()`](#toquerylocator)
210214

211215
## INIT
@@ -2558,6 +2562,8 @@ Map<Id, Account> idToAccount = (Map<Id, Account>) SOQL.of(Account.SObjectType).t
25582562

25592563
### toMap with custom key
25602564

2565+
**Note!** To improve query performance, a condition checking if the keyField is not null (`WHERE keyField != null`) is automatically added to the query.
2566+
25612567
**Signature**
25622568

25632569
```apex
@@ -2572,6 +2578,8 @@ Map<String, Account> nameToAccount = (Map<String, Account>) SOQL.of(Account.SObj
25722578

25732579
### toMap with custom relationship key
25742580

2581+
**Note!** To improve query performance, a condition checking if the targetKeyField is not null (`WHERE relationshipName.targetKeyField != null`) is automatically added to the query.
2582+
25752583
**Signature**
25762584

25772585
```apex
@@ -2586,6 +2594,8 @@ Map<String, Account> parentCreatedByEmailToAccount = (Map<String, Account>) SOQL
25862594

25872595
### toMap with custom key and value
25882596

2597+
**Note!** To improve query performance, a condition checking if the keyField is not null (`WHERE keyField != null`) is automatically added to the query.
2598+
25892599
**Signature**
25902600

25912601
```apex
@@ -2600,6 +2610,8 @@ Map<String, String> nameToAccount = SOQL.of(Account.SObjectType).toMap(Account.N
26002610

26012611
### toAggregatedMap
26022612

2613+
**Note!** To improve query performance, a condition checking if the keyField is not null (`WHERE keyField != null`) is automatically added to the query.
2614+
26032615
**Signature**
26042616

26052617
```apex
@@ -2614,6 +2626,8 @@ Map<String, List<Account>> industryToAccounts = (Map<String, List<Account>>) SOQ
26142626

26152627
### toAggregatedMap with custom value
26162628

2629+
**Note!** To improve query performance, a condition checking if the keyField is not null (`WHERE keyField != null`) is automatically added to the query.
2630+
26172631
**Signature**
26182632

26192633
```apex
@@ -2628,6 +2642,8 @@ Map<String, List<String>> industryToAccounts = SOQL.of(Account.SObjectType).toAg
26282642

26292643
### toAggregatedMap with custom relationship key
26302644

2645+
**Note!** To improve query performance, a condition checking if the targetKeyField is not null (`WHERE relationshipName.targetKeyField != null`) is automatically added to the query.
2646+
26312647
**Signature**
26322648

26332649
```apex
@@ -2640,6 +2656,78 @@ Map<String, List<SObject>> toAggregatedMap(String relationshipName, SObjectField
26402656
Map<String, List<Account>> parentCreatedByEmailToAccounts = (Map<String, List<Account>>) SOQL.of(Account.SObjectType).toAggregatedMap('Parent.CreatedBy', User.Email);
26412657
```
26422658

2659+
### toIdMapBy
2660+
2661+
Creates a map where the key is the Id extracted from the specified field and the value is the SObject record.
2662+
2663+
**Note!** To improve query performance, a condition checking if the field is not null (`WHERE field != null`) is automatically added to the query.
2664+
2665+
**Signature**
2666+
2667+
```apex
2668+
Map<Id, SObject> toIdMapBy(SObjectField field)
2669+
```
2670+
2671+
**Example**
2672+
2673+
```apex
2674+
Map<Id, Account> ownerIdToAccount = (Map<Id, Account>) SOQL.of(Account.SObjectType).toIdMapBy(Account.OwnerId);
2675+
```
2676+
2677+
### toIdMapBy with relationship
2678+
2679+
Creates a map where the key is the Id extracted from the specified relationship field and the value is the SObject record.
2680+
2681+
**Note!** To improve query performance, a condition checking if the targetKeyField is not null (`WHERE relationshipName.targetKeyField != null`) is automatically added to the query.
2682+
2683+
**Signature**
2684+
2685+
```apex
2686+
Map<Id, SObject> toIdMapBy(String relationshipName, SObjectField targetKeyField)
2687+
```
2688+
2689+
**Example**
2690+
2691+
```apex
2692+
Map<Id, Account> parentIdToAccount = (Map<Id, Account>) SOQL.of(Account.SObjectType).toIdMapBy('Parent', Account.Id);
2693+
```
2694+
2695+
### toAggregatedIdMapBy
2696+
2697+
Creates a map where the key is the Id extracted from the specified field and the value is a list of SObject records grouped by that Id.
2698+
2699+
**Note!** To improve query performance, a condition checking if the keyField is not null (`WHERE keyField != null`) is automatically added to the query.
2700+
2701+
**Signature**
2702+
2703+
```apex
2704+
Map<Id, List<SObject>> toAggregatedIdMapBy(SObjectField keyField)
2705+
```
2706+
2707+
**Example**
2708+
2709+
```apex
2710+
Map<Id, List<Account>> ownerIdToAccounts = (Map<Id, List<Account>>) SOQL.of(Account.SObjectType).toAggregatedIdMapBy(Account.OwnerId);
2711+
```
2712+
2713+
### toAggregatedIdMapBy with relationship
2714+
2715+
Creates a map where the key is the Id extracted from the specified relationship field and the value is a list of SObject records grouped by that Id.
2716+
2717+
**Note!** To improve query performance, a condition checking if the targetKeyField is not null (`WHERE relationshipName.targetKeyField != null`) is automatically added to the query.
2718+
2719+
**Signature**
2720+
2721+
```apex
2722+
Map<Id, List<SObject>> toAggregatedIdMapBy(String relationshipName, SObjectField targetKeyField)
2723+
```
2724+
2725+
**Example**
2726+
2727+
```apex
2728+
Map<Id, List<Account>> parentIdToAccounts = (Map<Id, List<Account>>) SOQL.of(Account.SObjectType).toAggregatedIdMapBy('Parent', Account.Id);
2729+
```
2730+
26432731
### toQueryLocator
26442732

26452733
**Signature**

website/docs/soql/examples/result.md

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,94 @@ Map<String, List<String>> accountNamesByIndustry = SOQL.of(Account.SObjectType)
368368
.toAggregatedMap(Account.Industry, Account.Name);
369369
```
370370

371+
## toIdMapBy
372+
373+
**Apex**
374+
375+
```apex title="Traditional Approach"
376+
Map<Id, Account> ownerIdToAccount = new Map<Id, Account>();
377+
378+
for (Account acc : [SELECT Id, Name, OwnerId FROM Account WHERE OwnerId != null]) {
379+
ownerIdToAccount.put(acc.OwnerId, acc);
380+
}
381+
```
382+
383+
**SOQL Lib**
384+
385+
```apex title="SOQL Lib Approach"
386+
Map<Id, Account> ownerIdToAccount = (Map<Id, Account>) SOQL.of(Account.SObjectType)
387+
.with(Account.Id, Account.Name)
388+
.toIdMapBy(Account.OwnerId);
389+
```
390+
391+
## toIdMapBy with relationship
392+
393+
**Apex**
394+
395+
```apex title="Traditional Approach"
396+
Map<Id, Account> parentIdToAccount = new Map<Id, Account>();
397+
398+
for (Account acc : [SELECT Id, Name, Parent.Id FROM Account WHERE Parent.Id != null]) {
399+
parentIdToAccount.put(acc.Parent.Id, acc);
400+
}
401+
```
402+
403+
**SOQL Lib**
404+
405+
```apex title="SOQL Lib Approach"
406+
Map<Id, Account> parentIdToAccount = (Map<Id, Account>) SOQL.of(Account.SObjectType)
407+
.with(Account.Id, Account.Name)
408+
.toIdMapBy('Parent', Account.Id);
409+
```
410+
411+
## toAggregatedIdMapBy
412+
413+
**Apex**
414+
415+
```apex title="Traditional Approach"
416+
Map<Id, List<Account>> ownerIdToAccounts = new Map<Id, List<Account>>();
417+
418+
for (Account acc : [SELECT Id, Name, OwnerId FROM Account WHERE OwnerId != null]) {
419+
if (!ownerIdToAccounts.containsKey(acc.OwnerId)) {
420+
ownerIdToAccounts.put(acc.OwnerId, new List<Account>());
421+
}
422+
423+
ownerIdToAccounts.get(acc.OwnerId).add(acc);
424+
}
425+
```
426+
427+
**SOQL Lib**
428+
429+
```apex title="SOQL Lib Approach"
430+
Map<Id, List<Account>> ownerIdToAccounts = (Map<Id, List<Account>>) SOQL.of(Account.SObjectType)
431+
.with(Account.Id, Account.Name)
432+
.toAggregatedIdMapBy(Account.OwnerId);
433+
```
434+
435+
## toAggregatedIdMapBy with relationship
436+
437+
**Apex**
438+
439+
```apex title="Traditional Approach"
440+
Map<Id, List<Account>> parentIdToAccounts = new Map<Id, List<Account>>();
441+
442+
for (Account acc : [SELECT Id, Name, Parent.Id FROM Account WHERE Parent.Id != null]) {
443+
if (!parentIdToAccounts.containsKey(acc.Parent.Id)) {
444+
parentIdToAccounts.put(acc.Parent.Id, new List<Account>());
445+
}
446+
447+
parentIdToAccounts.get(acc.Parent.Id).add(acc);
448+
}
449+
```
450+
451+
**SOQL Lib**
452+
453+
```apex title="SOQL Lib Approach"
454+
Map<Id, List<Account>> parentIdToAccounts = (Map<Id, List<Account>>) SOQL.of(Account.SObjectType)
455+
.with(Account.Id, Account.Name)
456+
.toAggregatedIdMapBy('Parent', Account.Id);
457+
```
458+
371459
## toQueryLocator
372460

373461
**Apex**
@@ -379,5 +467,7 @@ Database.QueryLocator queryLocator = Database.getQueryLocator('SELECT Id FROM AC
379467
**SOQL Lib**
380468

381469
```apex title="SOQL Lib Approach"
382-
Database.QueryLocator queryLocator = SOQL.of(Account.SObjectType).toQueryLocator();
470+
Database.QueryLocator queryLocator = SOQL.of(Account.SObjectType)
471+
.with(Account.Id, Account.Name)
472+
.toQueryLocator();
383473
```

0 commit comments

Comments
 (0)