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

Last login field in formula field



I am trying to use the LastLoginDate from user object to be used in a custom object. But i cant seem to find the field in the formula editor.


Is there a way we can do it?


You can’t access the LastLoginDate field in formula field because it is not exposable anymore in database, so you can write a trigger*(before inser,before update) on custom object to fill a field in a custom object based on user. Here below is the code that may help you.

trigger Testtrigger on PTOReq__c (before insert,before update) 
                user us=[select LastLoginDate from user where id=:UserInfo.getuserid()];
                account acc=[select name,newpakge__lastlogintimes__c from account where id='00190000009i5qo'];
                update acc;


Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.