-
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

How Salesforce’s Acquisition of Slack Will Reshape the Market
Salesforce acquiring Slack has been the talk of the town for a while. The deal finally got a green light on December 01, 2020, when…

Tips On How To Choose The Best Among The Salesforce Consulting Companies
Do you wish to deliver unparalleled customer services which can constantly increase your business bottom line? This is one thing that you can achieve only…
Popular Salesforce Videos
Salesforce Visualforce and Force.com Development Tutorial || Beginner
Learn to set up a web page using force.com and create forms for users to input information into Salesforce. For more Salesforce tips and tricks…
Data Loader Alternative | Export and Import Data Using Salesforce Inspector
Find out how to export and import data using Salesforce Inspector, a very useful alternative to traditional data loader. watch this video and learn all…
Topics to Master to Crack Your Salesforce Administrator Certification Exam
If you're preparing for your Salesforce Administrator Certification and wondering there's a lot that you need to cover from the study material provided by Salesforce.…