Skip to content

Commit d8a6a3d

Browse files
committed
minor adjustments
1 parent 08f931e commit d8a6a3d

File tree

6 files changed

+14
-41
lines changed

6 files changed

+14
-41
lines changed

sfdx-source/apex-common-samplecode/main/classes/batchjobs/CreateInvoicesJob.cls

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@
3131
* focusing on passing parameters in and handling errors and notifications
3232
*
3333
**/
34-
global with sharing class CreateInvoicesJob
34+
public with sharing class CreateInvoicesJob
3535
implements System.Schedulable, Database.Batchable<SObject>, Database.Stateful
3636
{
3737
// Simple job log for errors
3838
private List<JobError> jobErrors = new List<JobError>();
3939

40-
global void execute(SchedulableContext sc)
40+
public void execute(SchedulableContext sc)
4141
{
4242
// Start the job once the scheduled time has arrived
4343
Database.executeBatch(new CreateInvoicesJob());

sfdx-source/apex-common-samplecode/main/classes/service/OpportunitiesService.cls

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,19 @@
2424
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2525
**/
2626

27-
global with sharing class OpportunitiesService
27+
public with sharing class OpportunitiesService
2828
{
29-
global static void applyDiscounts(Set<Id> opportunityIds, Decimal discountPercentage)
29+
public static void applyDiscounts(Set<Id> opportunityIds, Decimal discountPercentage)
3030
{
3131
service().applyDiscounts(opportunityIds, discountPercentage);
3232
}
3333

34-
global static Set<Id> createInvoices(Set<Id> opportunityIds, Decimal discountPercentage)
34+
public static Set<Id> createInvoices(Set<Id> opportunityIds, Decimal discountPercentage)
3535
{
3636
return service().createInvoices(opportunityIds, discountPercentage);
3737
}
3838

39-
global static Id submitInvoicingJob()
39+
public static Id submitInvoicingJob()
4040
{
4141
return service().submitInvoicingJob();
4242
}

sfdx-source/apex-common-samplecode/main/classes/service/OpportunitiesServiceImpl.cls

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,18 @@ public class OpportunitiesServiceImpl
4242
);
4343
}
4444

45-
public void applyDiscounts(IOpportunities opportunitiesWithProducts, Decimal discountPercentage)
45+
private void applyDiscounts(IOpportunities opportunitiesWithProducts, Decimal discountPercentage)
4646
{
4747
// Create unit of work to capture work and commit it under one transaction
4848
fflib_ISObjectUnitOfWork uow = Application.UnitOfWork.newInstance();
4949

50-
applyDiscounts(uow, opportunitiesWithProducts, discountPercentage);
50+
// applyDiscounts(uow, opportunitiesWithProducts, discountPercentage);
51+
opportunitiesWithProducts.applyDiscount(discountPercentage, uow);
5152

5253
// Commit updates to opportunities
5354
uow.commitWork();
5455
}
5556

56-
public void applyDiscounts(fflib_ISObjectUnitOfWork uow, IOpportunities opportunitiesWithProducts, Decimal discountPercentage)
57-
{
58-
opportunitiesWithProducts.applyDiscount(discountPercentage, uow);
59-
}
60-
6157
public Set<Id> createInvoices(Set<Id> opportunityIds, Decimal discountPercentage)
6258
{
6359
// Create unit of work to capture work and commit it under one transaction

sfdx-source/apex-common-samplecode/main/classes/triggerHandlers/OpportunitiesTriggerHandler.cls

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -31,29 +31,6 @@ public class OpportunitiesTriggerHandler extends fflib_SObjectDomain
3131
// Domain classes are initialised with lists to enforce bulkification throughout
3232
super(sObjectList);
3333
}
34-
35-
public void generate(InvoicingService.InvoiceFactory invoiceFactory)
36-
{
37-
// Utilise InvoiceFactory to create invoices from Opportunity details
38-
for(Opportunity opportunity : (List<Opportunity>) this.records)
39-
{
40-
InvoicingService.Invoice invoice = new InvoicingService.Invoice();
41-
invoice.Account = opportunity.AccountId;
42-
invoice.Description = opportunity.Description;
43-
invoice.InvoiceDate = opportunity.CloseDate.addDays(14);
44-
invoice.Lines = new List<InvoicingService.InvoiceLine>();
45-
for(OpportunityLineItem lineItem : opportunity.OpportunityLineItems)
46-
{
47-
InvoicingService.InvoiceLine invoiceLineItem = new InvoicingService.InvoiceLine();
48-
invoiceLineItem.Description = lineItem.Description;
49-
invoiceLineItem.Product = lineItem.PricebookEntry.Product2Id;
50-
invoiceLineItem.UnitPrice = lineItem.UnitPrice;
51-
invoiceLineItem.Quantity = lineItem.Quantity;
52-
invoice.Lines.add(invoiceLineItem);
53-
}
54-
invoiceFactory.add(invoice);
55-
}
56-
}
5734

5835
public override void onApplyDefaults()
5936
{
@@ -69,7 +46,7 @@ public class OpportunitiesTriggerHandler extends fflib_SObjectDomain
6946
// Validate OpportunityTriggerHandler
7047
for(Opportunity opp : (List<Opportunity>) this.records)
7148
{
72-
if(opp.Type!=null && opp.Type.startsWith('Existing') && opp.AccountId == null)
49+
if(opp.Type != null && opp.Type.startsWith('Existing') && opp.AccountId == null)
7350
{
7451
opp.AccountId.addError( error('You must provide an Account for OpportunityTriggerHandler for existing Customers.', opp, Opportunity.AccountId) );
7552
}
@@ -79,10 +56,10 @@ public class OpportunitiesTriggerHandler extends fflib_SObjectDomain
7956
public override void onValidate(Map<Id,SObject> existingRecords)
8057
{
8158
// Validate changes to OpportunityTriggerHandler
82-
for(Opportunity opp : (List<Opportunity>) this.records)
59+
for (Opportunity opp : (List<Opportunity>) this.records)
8360
{
8461
Opportunity existingOpp = (Opportunity) existingRecords.get(opp.Id);
85-
if(opp.Type != existingOpp.Type)
62+
if (opp.Type != existingOpp.Type)
8663
{
8764
opp.Type.addError( error('You cannot change the Opportunity type once it has been created.', opp, Opportunity.Type) );
8865
}
@@ -97,7 +74,7 @@ public class OpportunitiesTriggerHandler extends fflib_SObjectDomain
9774
private void updateOpportunityActivityOnAccount()
9875
{
9976
Set<Id> accountIds =
100-
Opportunities.newInstance(this.Records)
77+
Opportunities.newInstance(this.records)
10178
.getAccountIds();
10279

10380
if (accountIds.isEmpty()) return;

sfdx-source/apex-common-samplecode/test/classes/service/OpportunitiesServiceTestIntegration.cls renamed to sfdx-source/apex-common-samplecode/test/classes/service/OpportunitiesServiceIntegrationTest.cls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
**/
2626

2727
@IsTest
28-
private class OpportunitiesServiceTestIntegration
28+
private class OpportunitiesServiceIntegrationTest
2929
{
3030
@IsTest
3131
private static void testServiceClass()

0 commit comments

Comments
 (0)