Skip to content

Commit 2c595c6

Browse files
committed
Minor changs for Trailhead Module updates
Changes made: * Moved `OpportunityInfo` out to a standalone class in order to allow it to be directly referenced by the `IOpportuntitesSelector` interface * Updated the `IOpportuntitesSelector` interface to include all public methods which is standard practice. * Minor tweaks to `OpportunitiesSelector` to improve readability. * Added `Opportunity.Amount` to the query factory in the `OpportunitiesSelector.selectOpportunityInfo(Set<Id>)` method to fix Trailhead Issue TCF-022057
1 parent 3c9195a commit 2c595c6

File tree

4 files changed

+39
-22
lines changed

4 files changed

+39
-22
lines changed

sfdx-source/apex-common-samplecode/main/classes/selectors/IOpportunitiesSelector.cls

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,8 @@
2626

2727
public interface IOpportunitiesSelector extends fflib_ISObjectSelector
2828
{
29+
List<Opportunity> selectById(Set<Id> idSet);
2930
List<Opportunity> selectByIdWithProducts(Set<Id> idSet);
31+
List<OpportunityInfo> selectOpportunityInfo(Set<Id> idSet);
32+
Database.QueryLocator queryLocatorReadyToInvoice();
3033
}

sfdx-source/apex-common-samplecode/main/classes/selectors/OpportunitiesSelector.cls

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -82,34 +82,26 @@ public class OpportunitiesSelector extends fflib_SObjectSelector
8282
public List<OpportunityInfo> selectOpportunityInfo(Set<Id> idSet)
8383
{
8484
List<OpportunityInfo> opportunityInfos = new List<OpportunityInfo>();
85-
for(Opportunity opportunity : Database.query(
86-
newQueryFactory(false).
87-
selectField(opportunity.Id).
88-
selectField(opportunity.StageName).
89-
selectField('Account.Name').
90-
selectField('Account.AccountNumber').
91-
selectField('Account.Owner.Name').
92-
setCondition('id in :idSet').
93-
toSOQL()))
85+
86+
for(Opportunity opportunity : Database.query( newQueryFactory(false)
87+
.selectField(Opportunity.Id)
88+
.selectField(Opportunity.StageName)
89+
.selectField(Opportunity.Amount)
90+
.selectField('Account.Name')
91+
.selectField('Account.AccountNumber')
92+
.selectField('Account.Owner.Name')
93+
.setCondition('id in :idSet')
94+
.toSOQL() ))
95+
{
9496
opportunityInfos.add(new OpportunityInfo(opportunity));
97+
}
98+
9599
return opportunityInfos;
96100
}
97101

98102
public Database.QueryLocator queryLocatorReadyToInvoice()
99103
{
100104
return Database.getQueryLocator(
101-
newQueryFactory().setCondition('InvoicedStatus__c = \'\'Ready\'\'').toSOQL());
102-
}
103-
104-
public class OpportunityInfo
105-
{
106-
private Opportunity opportunity;
107-
public Id Id { get { return opportunity.Id; } }
108-
public Decimal Amount { get { return opportunity.Amount; } }
109-
public String Stage { get { return opportunity.StageName; } }
110-
public String AccountName { get { return opportunity.Account.Name; } }
111-
public String AccountNumber { get { return opportunity.Account.AccountNumber; } }
112-
public String AccountOwner { get { return opportunity.Account.Owner.Name; } }
113-
private OpportunityInfo(Opportunity opportunity) { this.opportunity = opportunity; }
105+
newQueryFactory().setCondition(Opportunity.InvoicedStatus__c + ' = \'Ready\'').toSOQL());
114106
}
115107
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
public class OpportunityInfo
2+
{
3+
private Opportunity opportunity;
4+
5+
public OpportunityInfo(Opportunity opportunity)
6+
{
7+
this.opportunity = opportunity;
8+
}
9+
10+
public Id Id { get { return this.opportunity.Id; } }
11+
public Decimal Amount { get { return this.opportunity.Amount; } }
12+
public String Stage { get { return this.opportunity.StageName; } }
13+
public String AccountName { get { return this.opportunity.Account.Name; } }
14+
public String AccountNumber { get { return this.opportunity.Account.AccountNumber; } }
15+
public String AccountOwner { get { return this.opportunity.Account.Owner.Name; } }
16+
17+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
3+
<apiVersion>55.0</apiVersion>
4+
<status>Active</status>
5+
</ApexClass>

0 commit comments

Comments
 (0)