function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Eric VEric V 

Use Apex in Transaction Security Policies Challenge

Hi,

I'm trying to complete the "Use Apex in Transaction Security Policies" Challenge.

I think i have to modify this apex class : 
1 global class NewUrlPolicyCondition implements TxnSecurity.PolicyCondition {
2
3  public boolean evaluate(TxnSecurity.Event e) {
4
5  return false; 
6 }
7  }

The problem is that I know nothing about code, class or whatever. 
Can someone tell me how to set a condition ? 

Thanks. 
Best Answer chosen by Eric V
LABBOOLABBOO
Hi Eric! 
I just got this one.  
Basically, I had to first remove the New URL Transaction Security Policy I created in the earlier unit and also delete the NewURLPolicyCondition class it created.
Then I re-created by New URL Transaction Security Policy - but with a condition (any one of them) with a criteria of 2 days.
Then you'll be able to go in and edit the class per what you need to do for the challenge on this one.

Lynda

All Answers

LABBOOLABBOO
Hi Eric! 
I just got this one.  
Basically, I had to first remove the New URL Transaction Security Policy I created in the earlier unit and also delete the NewURLPolicyCondition class it created.
Then I re-created by New URL Transaction Security Policy - but with a condition (any one of them) with a criteria of 2 days.
Then you'll be able to go in and edit the class per what you need to do for the challenge on this one.

Lynda
This was selected as the best answer
Ryan Patten 24Ryan Patten 24
I think there have been updates to this Module, and I am having issues completing, not an APEX master (yet!)

Its asking for the following..
1.Modify the following apex class: newurlPolicyCondition
2. Change the platform condition
3. Old platform condition value: eObj.Platform == 'useanewtrailheadplayground'
4. New platform condition value: eObj.Platform == 'besupercarefulwiththis'

Any help here would be great!
Jake Harris 12Jake Harris 12
I had a heck of a time with this, but found this:
https://trailhead.salesforce.com/en/modules/transaction_security/units/transaction_security_custom_policy

Which had this:
global class BlockAndroidPolicyCondition implements TxnSecurity.PolicyCondition {
  public boolean evaluate(TxnSecurity.Event e) {
    LoginHistory eObj = [SELECT Platform FROM LoginHistory
                         WHERE Id = :e.data.get('LoginHistoryId')];
    if (eObj != null) {  // Addition
      if(eObj.Platform == 'Android 9') {
        return true;
      }
    }  // Addition
    return false;
  }
}



And then modified it to use the text above and ended up with this:
 
global class newurlPolicyCondition implements TxnSecurity.PolicyCondition {

 public boolean evaluate(TxnSecurity.Event e) {
LoginHistory eObj = [SELECT Platform FROM LoginHistory
                         WHERE Id = :e.data.get('LoginHistoryId')];
    if (eObj != null) {  // Addition
      if(eObj.Platform == 'besupercarefulwiththis') {
        return true;
      }
    }  // Addition
    return false;
  }
 }

 
Nick Beach 2Nick Beach 2
That just worked perfectly for me. Not sure how though but I'll take it