1 réponse
Sorry,Forgot to add trigger along with the Batch class.global class AccountBatchApex implements Database.Batchable<sObject>,Database.RaisesPlatformEvents{ //Database.RaisesPlatformEvents //global integer numberofDirectCustomers = 0; //integer counter=0; global Database.QueryLocator start(Database.BatchableContext bc){ String soqlQuery = 'SELECT Name, AccountNumber, Type From Account limit 10'; return Database.getQueryLocator(soqlQuery); } global void execute(Database.BatchableContext bc, List<Account> scope){ List<Account>acc12=new list<Account>(); for (Account acc : scope){ Account a=new account(Name='NYTimes',AccountNumber='1234567890'); acc12.add(a); } Update Acc12; } global void finish(Database.BatchableContext bc){ }}Here it comes.trigger MarkDirtyIfFail on BatchApexErrorEvent (after insert) { Set<Id> asyncApexJobIds = new Set<Id>(); for(BatchApexErrorEvent evt:Trigger.new){ System.debug('I am in for loop of the Trigger'+evt); asyncApexJobIds.add(evt.AsyncApexJobId); } Map<Id,AsyncApexJob> jobs = new Map<Id,AsyncApexJob>( [SELECT id, ApexClass.Name FROM AsyncApexJob WHERE Id IN :asyncApexJobIds] ); List<Account> records = new List<Account>(); for(BatchApexErrorEvent evt:Trigger.new){ //only handle events for the job(s) we care about // System.debug('I am in a another for loop of the Trigger'+evt); if(jobs.get(evt.AsyncApexJobId).ApexClass.Name == 'AccountBatchApex'){ for (String item : evt.JobScope.split(',')) { System.debug('I am in the third for loop'+item); Account a = new Account( Id = (Id)item, ExceptionType__c = evt.ExceptionType, Dirty__c = true ); records.add(a); } } } update records;}Once again:-Is BatchApexErrorEvent is still Beta or available to all users.?Is it possible to query this object?