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
MaheshwarMaheshwar 

Test coverage for "SELECT LoginGeoId FROM LoginHistory"

Hi,

My method will return true if there are any records in the LoginHistory for the currently logged in User in the last two hours.
Now, I'm trying to create a test class to cover this method.
So, in the test class, I need to login to salesforce org as a test user in order to create a record on LoginHistory.

Someone please help me with this scenario.

Thanks,
Mahesh
Somya TiwariSomya Tiwari

Hi Mahesh,

You will not need to Login to Salesforce Org in order to test. But you can simply create a test record in LoginHistory via the @TestSetup method. This is quite easy and then check if your method is giving the required result as you demanded. Test methods run in isolation and hence you will not get Actual Login Details.

Give a like if my answer helped you in any way.

MaheshwarMaheshwar
Hi Somya,

Thank you so much for responding.
I tried to insert a record in LoginHistory. However, it said "DML operation Insert not allowed on LoginHistory".
Is there anything that I'm missing?


Thanks,
Mahesh
Marko Balant 1Marko Balant 1
Hi, were you able to solve this issue and write a test for LoginHistory, I have the same issue?
Thanks.