Skip to content

Commit b175dc6

Browse files
John M. DanielJohn M. Daniel
authored andcommitted
Changes made:
Accounts.cls - changed "onAfterInsert" method to call on the Accounts domain via the domain factory and the Opportunities domain will work only with the "IAccounts" interface. - Used the "Application.Domain.newInstance(Set<ID>)" method to automatically select the records verses using an inline query. - Now working with the "fflib_ISObjectUnitOfWork" interface Application.cls - Added entry for Account.SObjectType to the SelectorFactory call to all above changes to Accounts domain to work correctly.
1 parent decbf83 commit b175dc6

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

sfdx-source/apex-common-samplecode/main/classes/Application.cls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public class Application
5252
public static final fflib_Application.SelectorFactory Selector =
5353
new fflib_Application.SelectorFactory(
5454
new Map<SObjectType, Type> {
55+
Account.SObjectType => AccountsSelector.class,
5556
Opportunity.SObjectType => OpportunitiesSelector.class,
5657
OpportunityLineItem.SObjectType => OpportunityLineItemsSelector.class,
5758
PricebookEntry.SObjectType => PricebookEntriesSelector.class,

sfdx-source/apex-common-samplecode/main/classes/domains/Opportunities.cls

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,27 @@ public class Opportunities extends fflib_SObjectDomain
103103
public override void onAfterInsert()
104104
{
105105
// Related Accounts
106-
List<Id> accountIds = new List<Id>();
107-
for(Opportunity opp : (List<Opportunity>) Records)
108-
if(opp.AccountId!=null)
106+
Set<Id> accountIds = new Set<Id>();
107+
for(Opportunity opp : (List<Opportunity>) this.records)
108+
{
109+
if( opp.AccountId != null)
110+
{
109111
accountIds.add(opp.AccountId);
110-
111-
// Update last Opportunity activity on the related Accounts (via the Accounts domain class)
112-
fflib_SObjectUnitOfWork uow = new fflib_SObjectUnitOfWork(new Schema.SObjectType[] { Account.SObjectType });
113-
Accounts accounts = new Accounts([select Id, Name from Account where id in :accountIds]);
114-
accounts.updateOpportunityActivity(uow);
115-
uow.commitWork();
112+
}
113+
}
114+
115+
if ( ! accountIds.isEmpty() )
116+
{
117+
// Update last Opportunity activity on the related Accounts (via the Accounts domain class)
118+
fflib_ISObjectUnitOfWork uow = new fflib_SObjectUnitOfWork(new Schema.SObjectType[] { Account.SObjectType });
119+
120+
121+
IAccounts accounts = (IAccounts)Application.Domain.newInstance( accountIds );
122+
123+
accounts.updateOpportunityActivity(uow);
124+
125+
uow.commitWork();
126+
}
116127
}
117128

118129
public void applyDiscount(Decimal discountPercentage, fflib_ISObjectUnitOfWork uow)

0 commit comments

Comments
 (0)