Skip to content

Commit

Permalink
Version 1.3.0 - Remove Dependency on SFDX Trigger Factory, add CodeCo…
Browse files Browse the repository at this point in the history
…v pipeline for Coverage reports (#2)

* Use standard CodeCov.yml for Test Coverage reporting on push

* update package lock

* Adjust Triggers to use same principle, encapsulated in separate TriggerExecutor Class

* Remove dependency on sfdx trigger factory

* Remove Apex Job Metadata Type

* Adjust codecov report to only check when code changes, adjust docs

* Adjust version and promoted package

Co-authored-by: Dennis Grzyb <dennis.grzyb@outlook.com>
  • Loading branch information
dschibster and Dennis Grzyb authored Jan 7, 2022
1 parent 1e459b5 commit c752439
Show file tree
Hide file tree
Showing 22 changed files with 14,995 additions and 152 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: code-coverage
on:
push:
branches:
- master
pull_request:
branches:
- master
paths:
- "batch-orchestrator/*"

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Install Dependencies
run: npm install sfdx-cli
- name: Populate auth file
run: 'echo "${{ secrets.SFDX_AUTH_URL }}" > ./SALESFORCE_AUTH_URL.txt'
- name: Authenticate Dev Hub
run: "node_modules/sfdx-cli/bin/run force:auth:sfdxurl:store -f ./SALESFORCE_AUTH_URL.txt -a devhub -d"
- name: Create Scratch Org
run: node_modules/sfdx-cli/bin/run force:org:create --targetdevhubusername devhub --setdefaultusername --definitionfile config/project-scratch-def.json --setalias ciorg --durationdays 1
- name: Deploy source
run: node_modules/sfdx-cli/bin/run force:source:push
- name: Run Apex tests
run: node_modules/sfdx-cli/bin/run force:apex:test:run --codecoverage --resultformat human -d ./
- name: Upload code coverage for Apex to Codecov.io
uses: codecov/codecov-action@v1
with:
flags: Apex
- name: Delete Scratch Org
run: node_modules/sfdx-cli/bin/run force:org:delete --noprompt
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

# Installation
<div>
<span><a href="https://login.salesforce.com/packaging/installPackage.apexp?p0=04t09000000ijMpAAI" target="_blank">
<span><a href="https://login.salesforce.com/packaging/installPackage.apexp?p0=04t09000000ijNTAAY" target="_blank">
<img alt="Deploy to Salesforce"
src="https://github.com/dschibster/sfdx-batch-orchestrator/blob/master/resources/deploy_unlocked.png">
</a>
Expand All @@ -19,7 +19,7 @@
<div>
For your Sandbox:
<div><span>
<a href="https://test.salesforce.com/packaging/installPackage.apexp?p0=04t09000000ijMpAAI" target="_blank">
<a href="https://test.salesforce.com/packaging/installPackage.apexp?p0=04t09000000ijNTAAY" target="_blank">
<img alt="Deploy to Salesforce"
src="https://github.com/dschibster/sfdx-batch-orchestrator/blob/master/resources/deploy_unlocked.png">
</a></span><div>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
* @last modified on : 2021-10-12
* @last modified by : Dennis Grzyb
**/
public with sharing class BatchApexErrorEventHandler extends TriggerHandlerExtension {
public with sharing class BatchApexErrorEventHandler extends BatchOrchTriggerExecutor {
BatchApexErrorEventHelper helper;
String lastReplayId;

public BatchApexErrorEventHandler() {
super();
helper = new BatchApexErrorEventHelper((List<BatchApexErrorEvent>) Trigger.new);
helper = new BatchApexErrorEventHelper((List<BatchApexErrorEvent>) triggerNew);
}

public override void bulkAfter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@
* @last modified by : Dennis Grzyb
**/

public with sharing class BatchApexJobHandler extends TriggerHandlerExtension {
public with sharing class BatchApexJobHandler extends BatchOrchTriggerExecutor {
public BatchApexJobHelper helper = BatchApexJobHelper.getInstance();

public BatchApexJobHandler() {
super();
}

public override void beforeInsert(SObject so) {
Batch_Apex_Job__c apexJob = (Batch_Apex_Job__c) so;
helper.verifyBatchJob(apexJob);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
* @last modified by : Dennis Grzyb
**/

public without sharing class BatchApexStatusEventHandler extends TriggerHandlerExtension {
public without sharing class BatchApexStatusEventHandler extends BatchOrchTriggerExecutor {
BatchApexStatusEventHelper helper;
String lastReplayId;

public BatchApexStatusEventHandler() {
super();
helper = new BatchApexStatusEventHelper(Trigger.new);
helper = new BatchApexStatusEventHelper(triggerNew);
}

public override void bulkAfter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,9 @@
* @last modified by : dschibster
**/

public without sharing class BatchJobScheduleHandler extends TriggerHandlerExtension {
public without sharing class BatchJobScheduleHandler extends BatchOrchTriggerExecutor {
public static BatchJobScheduleHelper helper = BatchJobScheduleHelper.getInstance();

public BatchJobScheduleHandler() {
super();
}

public override void bulkBefore() {
if (Trigger.isInsert || Trigger.isUpdate) {
//Adjusts the CRON Expression to its new term after an update
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
/**
* @description : Resolves dependency on sfdx-trigger-factory by offsetting key
* functionality of the framework into a virtual class.
* @author : Dennis Grzyb
* @group : batch-job-scheduler
* @last modified on : 2022-01-07
* @last modified by : Dennis Grzyb
**/

public virtual class BatchOrchTriggerExecutor {
//Context relevant variables
public Map<Id, SObject> triggerNewMap;
public List<SObject> triggerNew;
public Map<Id, SObject> triggerOldMap;
public List<SObject> triggerOld;
public String triggerOperation;

//SObject Lists used within the Handler Classes
public List<sObject> lstInsert;
public List<sObject> lstUpsert;
public List<sObject> lstUpdate;
public List<sObject> lstDelete;

public BatchOrchTriggerExecutor() {
triggerNewMap = Trigger.newMap;
triggerNew = Trigger.new;
triggerOldMap = Trigger.oldMap;
triggerOld = Trigger.old;
triggerOperation = Trigger.OperationType.name();

lstInsert = new List<sObject>();
lstUpsert = new List<sObject>();
lstUpdate = new List<sObject>();
lstDelete = new List<sObject>();
}

public void execute() {
//Split the operationtype (for example AFTER_INSERT) into its two pieces to determine what we need.
List<String> operations = triggerOperation.split('_');
Boolean isBefore = operations[0] == 'BEFORE';
String dmlOperation = operations[1];

// Before Trigger
if (isBefore) {
// Call the bulk before to handle any caching of data and enable bulkification
bulkBefore();

switch on dmlOperation {
when 'DELETE' {
for (SObject obj : triggerOldMap.values()) {
beforeDelete(obj);
}
}
when 'INSERT' {
for (SObject obj : triggerNew) {
beforeInsert(obj);
}
}
when 'UPDATE' {
for (SObject obj : triggerNew) {
beforeUpdate(triggerOldMap.get(obj.Id), obj);
}
}
}
} else {
// Call the bulk after to handle any caching of data and enable bulkification
bulkAfter();

switch on dmlOperation {
when 'DELETE' {
for (SObject obj : triggerOldMap.values()) {
afterDelete(obj);
}
}
when 'INSERT' {
for (SObject obj : triggerNew) {
afterInsert(obj);
}
}
when 'UPDATE' {
for (SObject obj : triggerNew) {
afterUpdate(triggerOldMap.get(obj.Id), obj);
}
}
when 'UNDELETE' {
for (SObject obj : triggerNew) {
afterUndelete(obj);
}
}
}
}

// Perform any post processing
andFinally();
}

/**
* @description Helps you call methods or collect data that you need before the processing of data in a "before" Context
* Example: Caching of Data Before Insert to supplement the inputs given by your user. (Cache Related Object Data for your new records)
* @author mindsquare AG
*/
virtual public void bulkBefore() {
}

/**
* @description Helps you call methods or collect data that you need before the processing of data in an "after" Context
* Example: Caching of Data After Update to help determine if further Updates on other objects are necessary later on.
* @author mindsquare AG
*/
virtual public void bulkAfter() {
}

/**
* @description Called for every single record in a Before Insert Context. Do not use DML or SOQL in here as this will cause failures with bulk data processing.
* Typecast the parameters into the proper SObject type for proper dot notation.
* @author mindsquare AG
* @param newSObj The current SObject you are checking from Trigger.new. Typecast into the SObject's proper type to use dot notation (rec.field__c)
*/
virtual public void beforeInsert(SOBject newSObj) {
}

/**
* @description Called for every single record in a Before Insert Context. Do not use DML or SOQL in here as this will cause failures with bulk data processing.
* Typecast the parameters into the proper SObject type for proper dot notation.
* @author mindsquare AG
* @param oldSObj The current SObject you are checking from Trigger.old. Represents the record before it was updated
* @param newSObj The current SObject you are checking from Trigger.new. Represents the record as it will land on the database after the Trigger.
*/
virtual public void beforeUpdate(SOBject oldSObj, SOBject newSObj) {
}

/**
* @description Called for every single record in a Before Delete Context. Use to throw exceptions for your record, should you not be allowed to delete them.
* Do not use DML or SOQL in here as this will cause failures with bulk data processing.
* Typecast the parameters into the proper SObject type for proper dot notation.
* @author mindsquare AG
* @param oldSObj The current record that is iterated over
*/
virtual public void beforeDelete(SOBject oldSObj) {
}

/**
* @description Called for every single record in an After Insert Conetxt.
* Do not use DML or SOQL in here as this will cause failures with bulk data processing.
* @author mindsquare AG
* @param newSObj newSObj The newly inserted record (it now has an Id)
*/
virtual public void afterInsert(SOBject newSObj) {
}

/**
* @description Called for every single record in an After Update Conetxt.
* Do not use DML or SOQL in here as this will cause failures with bulk data processing.
* @author mindsquare AG
* @param oldSObj oldSObj The record as it was before the database update
* @param newSObj newSObj The record as it is on the database now after triggers
*/
virtual public void afterUpdate(SOBject oldSObj, SOBject newSObj) {
}

/**
* @description Called for every single record in an After Delete Conetxt.
* Do not use DML or SOQL in here as this will cause failures with bulk data processing.
* Typecast the parameters into the proper SObject type for proper dot notation.
* @author mindsquare AG
* @param oldSObj Single Deleted record
*/
virtual public void afterDelete(SOBject oldSObj) {
}

/**
* @description Called for every single record in an After Undelete Conetxt.
* Do not use DML or SOQL in here as this will cause failures with bulk data processing.
* Typecast the parameters into the proper SObject type for proper dot notation.
* @author mindsquare AG
* @param oldSObj Single Undeleted record
*/
virtual public void afterUndelete(SOBject oldSObj) {
}

/**
* @description Used for processing of data collected in record processing
* Use to commit new records to database or fire updates
* @author mindsquare AG
*/
virtual public void andFinally() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>52.0</apiVersion>
<status>Active</status>
</ApexClass>

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit c752439

Please sign in to comment.