Skip to main content

Use Apex to create a transaction security policy that blocks users who are not system administrators from exporting more than 100 records per report.  Prework: Enable Transaction Security Policies in your Trailhead Playground. (If you completed the previous challenge, you already did this.)

  • Create a Transaction Security policy using Apex:
    • Event: Report Event
    • Apex Class: New Empty Apex Class
    • Action: Block
    • Notifications: Email notification & In-App notification
    • Recipient: Choose a valid user
    • Name: Block Large Data Export
    • Status: Disabled
  • Edit the auto-generated BlockLargeDataExportEventCondition Apex class:
    • Replace the existing Apex code with the code in the Get Ready for the Hands-On Challenge section of this unit
    • Modify the Apex code:
      • Method to modify: evaluate(ReportEvent reportEvent)
      • Objective: If the user's profile is NOT System Administrator, prevent report exports of more than 100 records
    • enabled the Block Large Data Export policy

In the hands-on challenge, you create a Transaction Security policy using Apex. This is the code you use for the challenge. The challenge then asks you to make a few more changes to this code.

 

global class BlockLargeDataExportEventCondition implements TxnSecurity.EventCondition {     public boolean evaluate(SObject event) {         switch on event{             when ReportEvent reportEvent {                 return evaluate(reportEvent);             }             when null {                 // Don't take policy action when event is null                 return false;             }             when else{                 // Don't take policy action when event is not handled                 return false;             }         }     }     /**      * Handle evaluating ReportEvent      */     private boolean evaluate(ReportEvent reportEvent){         Profile profile = [SELECT Name FROM Profile WHERE Id IN                             (SELECT profileId FROM User WHERE Id = :reportEvent.UserId)];         // Take policy action only if the user profile is not 'Data Steward' and         // RowsProcessed greater than 10.         if (!profile.Name.contains('Data Steward')             && reportEvent.RowsProcessed > 100) {             return true;         }         return false;     } }

And always the same error:

We can’t find the expected code in the BlockLargeDataExportEventCondition Apex class. Make sure that the global class name is 'BlockLargeDataExportEventCondition', and that you modified the 'evaluate(ReportEvent reportEvent)' method.

5 respuestas
  1. 5 ene 2022, 13:41

    In your user profile, we cannot find the Time Zone set to '(GMT-:04:00) Venezuela time (America/Caracas)'.

    Is changed into usuario for spanish system.

0/9000