Skip to content

Commit 225cd22

Browse files
committed
documentation + examples update
1 parent 94e5b82 commit 225cd22

35 files changed

+789
-568
lines changed
Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,35 @@
11
public with sharing class ExampleController {
22

3-
// With Composition
4-
53
@AuraEnabled
64
public static List<Contact> getContactsByRecordType(String recordType) {
7-
return SOQL_Contact.byRecordType(recordType)
5+
return SOQL_Contact.query()
6+
.byRecordType(recordType)
87
.with(Contact.Email, Contact.Title)
98
.toList();
109
}
1110

1211
@AuraEnabled
1312
public static List<Contact> getContactsRelatedToAccount(Id accountId) {
14-
return SOQL_Contact.byAccountId(accountId).toList();
13+
return SOQL_Contact.query().byAccountId(accountId).toList();
1514
}
1615

1716
@AuraEnabled
1817
public static String getContactName(Id contactId) {
19-
return SOQL_Contact.toName(contactId);
18+
return SOQL_Contact.query().toName(contactId);
2019
}
2120

22-
// With Inheritance
23-
2421
@AuraEnabled
2522
public static List<Account> getPartnerAccounts(String accountName) {
26-
return new SOQL_Account()
23+
return SOQL_Account.query()
24+
.byRecordType('Partner')
2725
.with(Account.BillingCity, Account.BillingCountry)
28-
.whereAre(SOQL.FilterGroup
29-
.add(SOQL.Filter.name().contains(accountName))
30-
.add(SOQL.Filter.recordType().equal('Partner'))
31-
)
26+
.whereAre(SOQL.Filter.name().contains(accountName))
3227
.toList();
3328
}
3429

3530
@AuraEnabled
3631
public static List<Account> getAccountsByRecordType(String recordType) {
37-
return new SOQL_Account()
32+
return SOQL_Account.query()
3833
.byRecordType(recordType)
3934
.byIndustry('IT')
4035
.with(Account.Industry, Account.AccountSource)
@@ -43,24 +38,16 @@ public with sharing class ExampleController {
4338

4439
@AuraEnabled
4540
public static String getAccountIndustry(Id accountId) {
46-
return new SOQL_Account().toIndustry(accountId);
47-
}
48-
49-
// Standard (Old) Approach
50-
51-
@AuraEnabled
52-
public static List<Opportunity> getOpportunitiesByRecordType(String recordType) {
53-
return new SOQL_Opportunity().byRecordType(recordType);
41+
return SOQL_Account.query().toIndustry(accountId);
5442
}
5543

5644
@AuraEnabled
5745
public static List<Opportunity> getOpportunitiesRelatedToAccount(Id accountId) {
58-
return new SOQL_Opportunity().byAccountId(accountId);
46+
return SOQL_Opportunity.query().byAccountId(accountId).toList();
5947
}
6048

61-
6249
@AuraEnabled
6350
public static Integer getOpportunityAmount(Id opportunityId) {
64-
return new SOQL_Opportunity().toAmount(opportunityId);
51+
return SOQL_Opportunity.query().toAmount(opportunityId);
6552
}
6653
}

force-app/main/default/classes/example/inheritance/SOQL_Account.cls renamed to force-app/main/default/classes/example/SOQL_Account.cls

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1-
public inherited sharing class SOQL_Account extends SOQL {
2-
public SOQL_Account() {
1+
public inherited sharing class SOQL_Account extends SOQL implements SOQL.Selector {
2+
public static SOQL_Account query() {
3+
return new SOQL_Account();
4+
}
5+
6+
private SOQL_Account() {
37
super(Account.SObjectType);
48
// default settings
59
with(Account.Id, Account.Name, Account.Type)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
public inherited sharing class SOQL_Contact extends SOQL implements SOQL.Selector {
2+
public static SOQL_Contact query() {
3+
return new SOQL_Contact();
4+
}
5+
6+
private SOQL_Contact() {
7+
super(Contact.SObjectType);
8+
// default settings
9+
with(Contact.Id, Contact.Name, Contact.AccountId)
10+
.systemMode()
11+
.withoutSharing();
12+
}
13+
14+
public SOQL_Contact byRecordType(String rt) {
15+
whereAre(Filter.recordType().equal(rt));
16+
return this;
17+
}
18+
19+
public SOQL_Contact byAccountId(Id accountId) {
20+
whereAre(Filter.with(Contact.AccountId).equal(accountId));
21+
return this;
22+
}
23+
24+
public String toName(Id contactId) {
25+
return (String) query().byId(contactId).toValueOf(Contact.Name);
26+
}
27+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
public inherited sharing class SOQL_Opportunity extends SOQL implements SOQL.Selector {
2+
public static SOQL_Opportunity query() {
3+
return new SOQL_Opportunity();
4+
}
5+
6+
private SOQL_Opportunity() {
7+
super(Opportunity.SObjectType);
8+
// default settings
9+
with(Opportunity.Id, Opportunity.AccountId);
10+
}
11+
12+
public SOQL_Opportunity byAccountId(Id accountId) {
13+
whereAre(Filter.with(Opportunity.AccountId).equal(accountId));
14+
return this;
15+
}
16+
17+
public Integer toAmount(Id opportunityId) {
18+
return (Integer) query().byId(opportunityId).toValueOf(Opportunity.Amount);
19+
}
20+
}

force-app/main/default/classes/example/composition/SOQL_Contact.cls

Lines changed: 0 additions & 23 deletions
This file was deleted.

force-app/main/default/classes/example/standard/SOQL_Opportunity.cls

Lines changed: 0 additions & 22 deletions
This file was deleted.

website/docs/advanced-usage/_category_.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"label": "Advanced Usage",
3-
"position": 7,
3+
"position": 80,
44
"link": {
55
"type": "generated-index"
66
}

0 commit comments

Comments
 (0)