SHARE
TWEET

Untitled

a guest Jun 18th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. trigger LogBatchApexErrorEvent on BatchApexErrorEvent (after insert){
  2.     if(Trigger.IsInsert && Trigger.IsAfter){
  3.         LogBatchApexErrorEvent_Handler.persistLog(Trigger.New);
  4.     }
  5. }
  6.      
  7. public with sharing class TestBatch implements Database.Batchable<sObject>, Database.RaisesPlatformEvents {
  8.     public Database.QueryLocator start(Database.BatchableContext BC){
  9.         String query = 'SELECT Id FROM Account';
  10.         return Database.getQueryLocator(query);
  11.     }
  12.  
  13.     public void execute(Database.BatchableContext BC, List<SObject> scope){
  14.         Integer i = 1 / 0;
  15.     }
  16.  
  17.     public void finish(Database.BatchableContext BC){ }
  18. }
  19.      
  20. static testMethod void testBatchApexErrorEvent() {
  21.     insert new Account(Name = 'Test Account');
  22.  
  23.     try {
  24.         Test.startTest();
  25.             TestBatch tb = new TestBatch();
  26.             Database.executeBatch(tb);
  27.         Test.stopTest();
  28.     } catch(System.MathException e){}
  29.  
  30.     System.assertEquals(1, [SELECT Id FROM Log__c].size());
  31. }
  32.      
  33. BatchApexErrorEvent event = new BatchApexErrorEvent();
  34. EventBus.publish(event);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top