2

With Event Monitoring 2.0, I have successfully been able to create a class for Report Export Event. Can anyone assist with the Test Class, as all the field behind ReportEvent Big Object are non-editable. Than I am not able to create a Test Class for this.

public class ReportExportPolicyCondition implements TxnSecurity.EventCondition {

    public boolean evaluate(SObject event) {
      switch on event {
         when ReportEvent reportEvent {
            return handleReportEvent(reportEvent);
         }
         when null {
         // Trigger action if event is null
         return true;
         }
         when else {
         // Trigger action for unhandled events
         return true;
         }
      }
   }

   private boolean handleReportEvent(ReportEvent reportEvent){
      Integer mySequence = Integer.valueOf(reportEvent.Sequence);
      Boolean isReportScheduled = Boolean.valueOf(reportEvent.IsScheduled);
      if(reportEvent.Operation.contains('ReportExported') && mySequence < 2 && !isReportScheduled){ 
      return true;
      } 
      return false;
   }

}
@isTest(SeeAllData=true)
public class ReportExportPolicyConditionTest {

    @isTest
    static void TestReportPolicyExecuted() {

        ReportEvent myre = [SELECT EventSource, Sequence, Format, Operation, IsScheduled FROM ReportEvent LIMIT 1];

        ReportExportPolicyCondition cond = new ReportExportPolicyCondition();
        system.assertEquals(true, cond.evaluate(myre));

    }

}
  • WHat have you tried so far? – Pranay Jaiswal Aug 22 at 9:03
  • Hi Pranay, I have referred developer.salesforce.com/forums/?id=9060G000000UanjQAC but unfortunately as I cant create any record. So if - Seealldata=true, I have to rely on data already present (also I have to cover if there is no data present). Also, not able to understand how '01pR00000009D2H', /* entityId */ is coming up. – Varun SFDC Aug 22 at 9:13
  • Please do not apply tags which have nothing to do with what you are asking. – Adrian Larson Aug 22 at 13:06
  • Thanks Adrian for the correction. I will abide by it in the future – Varun SFDC Aug 22 at 13:14
  • Updated Test Class but as expected getting null pointer exception and 61% code coverage – Varun SFDC Aug 26 at 6:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.