• AVergaraPH
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
Has anyone tried setting up a transaction security policy for a specific report? I've tried this sample code in the documentation (https://developer.salesforce.com/docs/atlas.en-us.200.0.apexcode.meta/apexcode/apex_interface_TxnSecurity_PolicyCondition.htm) but I could not get it working in my developer org. When I checked the log, the event object content seems to be generic and the entityid which supposed to contain the report id is null.
My policy is set up as: 
Event Type: AccessResource
Resource: Reports and Dashboards
Action: Block /2 -factor auth
 
global class ConfidentialDataCondition implements TxnSecurity.PolicyCondition {
  public boolean evaluate(TxnSecurity.Event event) {
    if(event.resourceType == 'Reports'){  // If the event is about reports...
      List<Report> reports = [SELECT Name FROM Report WHERE Id = :event.entityId];
      if(reports.size() > 0){             // and if there’s a report...
        String name = (String) reports.get(0).get('Name');
        if(!String.isBlank(name) && name.containsIgnoreCase('Quarterly Report FY 2016')){
          return true;  // and if the name meets our criteria, trigger the policy.
        }
      }
    }
    return false;  // Otherwise the policy is not triggered.
  }
}