-
How can we Retrieve Last Login Date for a user based on Salesforce user licenses?
I want to retrive last login date of a user who has diffrent-2 licenses
i wrote some code, If i m chacking for "Salesforce" License ,it's working fine .
If i m tring for other licenses it's not working .
Can any one help me on this problem!!!!!!!!Public static List<Integer> ReturnAdoptionInfo(String LicenseType) { List<Integer> licensevalues = New List<Integer>(); Map<Id,Profile> profileIds = new Map<id,profile>([SELECT Id,UserLicenseId FROM Profile where UserLicenseId in (SELECT Id FROM UserLicense where name =:LicenseType)]); List<user> standardProfileUsers = [select id ,username,lastlogindate from user where profileId in:profileIds.Keyset() and usertype='standard' and isactive=true]; integer Lastlogin_30=0,Lastlogin_60=0,Lastlogin_90=0; for(user u :standardProfileUsers) { system.debug(u.lastlogindate); if(u.lastlogindate >= datetime.now()-30) { Lastlogin_30++; Lastlogin_60++; Lastlogin_90++; } else if(u.lastlogindate >= datetime.now()-60) { Lastlogin_60++; Lastlogin_90++; } else if(u.lastlogindate >= datetime.now()-90) { Lastlogin_90++; } } licensevalues.add(standardProfileUsers.size()); licensevalues.add(Lastlogin_30); licensevalues.add(Lastlogin_60); licensevalues.add(Lastlogin_90); // system.debug(licensevalues); return licensevalues; }please also check if this code is working fine or not !!!!!!!!!
Log In to reply.
Popular Salesforce Blogs
Salesforce Future Trends: 5 Major Trends to Watch Out For (2022 - 2023)
Salesforce trends for the year 2022-2023! Has it created too much buzz around? Well, possibly yes! Coz it is worth it… For more than two…
Why Should You Choose Salesforce Revenue Cloud & CPQ!
Streamline Your Lead to Cash Business Processes in a Single Unified Platform Salesforce Revenue Cloud Suite is part of the Salesforce Customer 360 platform. It is…
What is Einstein GPT? World's First Generative AI for CRM
Introduction Meet Salesforce's Einstein GPT, a new addition to the ever-expanding array of chatbots with AI capabilities. The service stands out slightly from the competition…
Popular Salesforce Videos
Translation Workbench | Salesforce Tutorial
One of the most common questions new Salesforce admins ask us is how can they translate custom terms when their org is in multiple languges?…
Salesforce App Builder Training | Salesforce App Builder Tutorial | Intellipaat
In this salesforce app builder tutorial, you will learn what is Salesforce CRM, a Sales rep in Salesforce, various user settings in Salesforce, and how…
Apex Classes and Apex Triggers in Salesforce
In this video, Salesforce developer Artem will demonstrate real-world applications of both Apex classes and triggers with practical business scenarios. Apex classes and Apex triggers…