• Brian Chong
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
I'm currently workng my way through Explore Custom Transaction Security Policies : Test the Apex for the Policy.
Perhaps at the time this module was written, the example code was valid.

However, presently: 
1. If I try to set the value of LoginHistory.platform, the Apex code is rejected with 
Error: Compile Error: Field is not writeable: LoginHistory.Platform at line 6 column 5

2. If I try to insert a LoginHistory record, the Apex code is rejected with
Error: Compile Error: DML operation INSERT not allowed on LoginHistory at line 7 column 5

I don't want to litter my production code with Test.isRunningTest().

While I could refactor the code to replace both the SOQL and the evaluation with injected dependency(s), such would leave the most critical portions of the class actually untested, which is likewise unsatisfactory.

Is it still possible to test the PolicyCondition?
Is there some trick I'm overlooking?