afawcett / force-brf Goto Github PK
View Code? Open in Web Editor NEWWork in progress reference lib for BatchApexErrorEvent handling
License: BSD 3-Clause "New" or "Revised" License
Work in progress reference lib for BatchApexErrorEvent handling
License: BSD 3-Clause "New" or "Revised" License
The execute method in the class brf_BatchableRetryJob will throw an exception when the batch operates on history sobjects i.e. accounthistory, claimhistory. CaseComment has the same issue
A sobject instance cannot be created for those types with the following call:
//errorId points to either claimhistory, casecomment etc
sObjectType.newSObject(errorId);
https://help.salesforce.com/s/articleView?id=000332227&type=1
I'm "solving" this with a switch case. However I'm not satisfied with this solution since I'll need to rewrite the brf_BatchableRetryJob.execute method each time a new batch is introduced that operates on the history objects/casecommments etc...
public void execute(Database.BatchableContext ctx, List<brf_BatchableError> scope) {
// One batch scope here represents an entire previously failed batch scope
brf_BatchableError error = scope[0];
// Construct an SObject scope to pass to the execute method
// TODO: Support non-SObject scopes
List<Id> scopeErrorIds = error.JobScope.split(',');
SObjectType sObjectType = scopeErrorIds[0].getSobjectType();
List<SObject> retryScope = new List<SObject>();
for (Id errorId : scopeErrorIds) {
SObject sObj = null;
switch on error.ApexClassName {
when 'BatchAccountHistory', 'BatchAccountHistory_2' {
sObj = Schema.getGlobalDescribe().get('AccountHistory').newSObject();
sObj.Id = errorId;
}
when 'ClaimHistory' {
sObj = Schema.getGlobalDescribe().get('ClaimHistory').newSObject();
sObj.Id = errorId;
}
when else {
sObj = sObjectType.newSObject(errorId);
}
}
if (sObj != null) {
retryScope.add(sObj);
}
}
// Invoke the execute method on the original batch apex job class
Type apexJobClassType = Type.forName(error.ApexClassName);
Database.Batchable<SObject> batchJob = (Database.Batchable<SObject>) apexJobClassType.newInstance();
batchJob.execute(ctx, retryScope);
}
An better solution for this issue would probably to extend the brf_BatchableErrorHandler interface with a method that returns the sobject type i.e. 'ClaimHistory' or 'Account' etc.. => then utilize that in the execute method
Deploy Setup
sfdc force:source:push // replace sfdc with sfdx
sfdx force:user:permset:assign --permsetname Billing
sfdx force:user:permset:assign --permsetname brf_BatchRetryFramework
Data Setup
sfdc force:apex:execute // replace sfdc with sfdx
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.