0

I have a requirement to view if someone else logged into community(experience site) as some user and made modifications. Currently as salesforce session change it shows lastModifiedBy the logged in user not the person who impersonated.

I have an object which is impacted by any modification the user(logged in as) makes. I want to create a field which will capture user who actually logs in.

Approach I tried:- Update trigger on concerned object and iteration on setupAuditTrail records to match the logged in user with user field of auditTrail object.This will be followed to break the loop once I get the matching record and update the newly created custom field = delegateUser.

Issues faced:- 1. I am getting delegateUser as blank in SOQL, however it appears correctly when I access it via org on UI(going to setup - searching for setup audit trail). 2. Can't filter by section. 3. Doc says that delegateUser gets the information unless user does not perform any action. However to my surprise it does not even though I perform the action.

Research tried : verdict: can't get this info but links are a bit old, so curious if some workaround/approach is available

  1. Do Login Flows Get Triggered when attepting to "Login As" another User?
  2. Getting user info when logged in as another user
  3. Getting user info when logged in as another user

1 Answer 1

1

I happened to be looking at the AuthSession object and wondered if that could be used, this approach may be overkill, inefficient or not practical but it piqued my interest :)

Not sure how well it would would work if both users were logged in though...

Query AuthSession something like:

SELECT Id,LoginHistoryIdUsersId,
FROM AuthSession
WHERE CreatedDate = TODAY AND SessionType = 'SubstituteUser' AND UsersId = :System.UserInfo.getUserId()

Get user name via LoginHistory like:

SELECT Name FROM User WHERE Id IN (SELECT UserId FROM LoginHistory WHERE Id = :loginAsAuthSessionId)

This looks like it will work as the LoginHistoryId is shared across both AuthSessions. Screenshot below shows this, UserIds AAK and AAJ share the same LoginHistory record, while AAJ has the SessionType of SubstituteUser

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .