Skip to main content The Trailblazer Community will be unavailable from 2/1/2025 to 2/2/2025. Please plan your activities accordingly.
I am looking to point to the last login time on the user object as part of a solution I am building. However neither the process builder nor formulas allow us to point to the standard out of the box user field called Last login time. I found a trigger on another thread that I could leverage

this is the trigger 

trigger lastLoginDate on User(before update){

User u = [SELECT LastLoginDate FROM User WHERE Id =:UserInfo.getUserId()];

for(User c : Trigger.new){        

    c.last_login__c= u.LastLoginDate;

    }

}

It works but I must hit the edit save button on the user record in order for the trigger to fire. What I need is for the trigger to fire when a user actaully logs in . I had assumed that a user logging in would fire the trigger by updating the standard last login field and therefore update my new custom last login field

Any ideas ?

I thought I could build a process to hit a refresh check box every day on all users, this may work as I only need the login day for the solution.

OR

Is there anyone who knows if I could treak the above trigger to fire when someone actaully logs in ?

 
2 answers
  1. Aug 30, 2019, 12:13 PM
    Hi Derek,

    Greetings to you!

    There's an idea which is active on the success community with a similar discussion for which you can upvote so that it gets available in the future.

    https://success.salesforce.com/ideaView?id=08730000000BowqAAC

    However, you can use the login flows:

    https://developer.salesforce.com/docs/atlas.en-us.securityImplGuide.meta/securityImplGuide/security_login_flow_examples.htm

    https://help.salesforce.com/articleView?id=security_login_flow.htm&type=5 (https://help.salesforce.com/articleView?id=security_login_flow.htm&type=5)

    Please refer to the following link, it has a couple of suggestion on how you can capture user login and perform an action:

    https://salesforce.stackexchange.com/questions/9926/execute-an-action-run-a-trigger-every-time-a-user-logs-in-to-salesforce

    I hope it helps you.

    Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

    Thanks and Regards,

    Khan Anas
Loading
0/9000