forked from ianhuang/Apex-Batch-Job-Scheduler
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Version 1.3.0 - Remove Dependency on SFDX Trigger Factory, add CodeCo…
…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
1 parent
1e459b5
commit c752439
Showing
22 changed files
with
14,995 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 0 additions & 21 deletions
21
...main/batch-job-management/customMetadata/TriggerFactorySetting.Batch_Apex_Job.md-meta.xml
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
188 changes: 188 additions & 0 deletions
188
batch-orchestrator/main/batch-job-scheduler/classes/BatchOrchTriggerExecutor.cls
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() { | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
batch-orchestrator/main/batch-job-scheduler/classes/BatchOrchTriggerExecutor.cls-meta.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
21 changes: 0 additions & 21 deletions
21
...tch-job-scheduler/customMetadata/TriggerFactorySetting.Batch_Apex_Error_Event.md-meta.xml
This file was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
.../main/batch-job-scheduler/customMetadata/TriggerFactorySetting.Batch_Apex_Job.md-meta.xml
This file was deleted.
Oops, something went wrong.
21 changes: 0 additions & 21 deletions
21
...ch-job-scheduler/customMetadata/TriggerFactorySetting.Batch_Apex_Status_Event.md-meta.xml
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.