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
Brian KesslerBrian Kessler 

How can I _actually_ currently modify LoginHistory for testing?

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?





 
Waqar Hussain SFWaqar Hussain SF
You can not modify or insert login History using apex code.
for more information see the below link.

You can only query login history
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_loginhistory.htm
Brian KesslerBrian Kessler
So, you are saying Apex for Transaction Security Policies are no longer testable and that the relevant portion of the module isn't merely broken but actually completely obsolete?
Charles ThompsonCharles Thompson
Yes, @Brian Kessler, that would appear to be the case.  This issue was logged with the Trailhead Feedback team over a year ago and the issue has not been resolved :-(
Brian ChongBrian Chong
I'm running into this same issue. I've posted an idea here: https://success.salesforce.com/ideaView?id=0873A000000LoH0QAK