Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. QA Testing
  3. Question
QA Testing

How to login salesforce users programmatically?

Asked by Amit Verma Jul 19, 2021 2.0K views 1 answer
Share

About this question

I require to login certain users among the test users created in test classes.

Each user is created as follows:

User user = new User(Alias='test', Email='test@none.com'); insert user;
I create multiple such sample users.
My business logic class checks for logged in users via:
List sessions = [Select UserId From AuthSession];

UserId in this list tells me which users are logged in. How can I login my user programmatically in my test case? Edit: I run a scheduled Apex class which assigns a particular lead from a Queue to one among list of users. Scheduler runs as Admin. It needs to check which among UserA, UserB or UserC is Logged in. To make this check I use AuthSession to determine which users are logged in. UserInfo contains information about Admin which is irrelevant. Under this light is there alternative to AuthSession? In test case, I create mock users and need to simulate some among them are logged in. So that I can test if my business logic works well to skip assignment for 'Not logged in users'.

Your answer

1 Answer

More QA Testing discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest QA Testing Blogs

Guides, tips and career advice on QA Testing from JanBask experts.