Toggle Side Panel

  • Home
  • Articles
    • All Articles
    • Blogs
    • Videos
    • Infographics
  • Consultants
    • Salesforce Product Expertise
      • Top Salesforce ConsultantsTop Salesforce Consultants
      • Marketing Cloud ConsultantsMarketing Cloud Consultants
      • Service Cloud ConsultantsService Cloud Consultants
      • Experience Cloud ConsultantsExperience Cloud Consultants
      • Analytics Cloud ConsultantsAnalytics Cloud Consultants
    • Salesforce Industry Expertise
      • Non-Profit Cloud ConsultantsNon-Profit Cloud Consultants
      • Financial Service Cloud ConsultantsFinancial Service Cloud Consultants
      • Health Cloud ConsultantsHealth Cloud Consultants
      • Commerce Cloud ConsultantsCommerce Cloud Consultants
      • Manufacturing Cloud ConsultantsManufacturing Cloud Consultants
    • Salesforce Experts by Location
      • USATop Salesforce Consultants in USA
      • IndiaTop Salesforce Consultants in India
      • AustraliaTop Salesforce Consultants in Australia
      • United KingdomTop Salesforce Consultants in UK
      • CanadaTop Salesforce Consultants in Canada
  • Webinars
  • Marketplace
  • Advertise With Us
  • Contact Us
  • Discussions
More options
    Sign in Sign up
    • Home
    • Articles
      • All Articles
      • Blogs
      • Videos
      • Infographics
    • Consultants
      • Salesforce Product Expertise
        • Top Salesforce ConsultantsTop Salesforce Consultants
        • Marketing Cloud ConsultantsMarketing Cloud Consultants
        • Service Cloud ConsultantsService Cloud Consultants
        • Experience Cloud ConsultantsExperience Cloud Consultants
        • Analytics Cloud ConsultantsAnalytics Cloud Consultants
      • Salesforce Industry Expertise
        • Non-Profit Cloud ConsultantsNon-Profit Cloud Consultants
        • Financial Service Cloud ConsultantsFinancial Service Cloud Consultants
        • Health Cloud ConsultantsHealth Cloud Consultants
        • Commerce Cloud ConsultantsCommerce Cloud Consultants
        • Manufacturing Cloud ConsultantsManufacturing Cloud Consultants
      • Salesforce Experts by Location
        • USATop Salesforce Consultants in USA
        • IndiaTop Salesforce Consultants in India
        • AustraliaTop Salesforce Consultants in Australia
        • United KingdomTop Salesforce Consultants in UK
        • CanadaTop Salesforce Consultants in Canada
    • Webinars
    • Marketplace
    • Advertise With Us
    • Contact Us
    • Discussions
    Close search

    Activity › Forums › Salesforce® Discussions › How can we Retrieve Last Login Date for a user based on Salesforce user licenses?

    Tagged: Login, Retrieve, Salesforce Licenses, Salesforce User Licenses, User Group, User in Salesforce, User License

    • Salesforce® Discussions

      How can we Retrieve Last Login Date for a user based on Salesforce user licenses?

      Posted by Gourav on May 28, 2019 at 11:57 AM

      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 !!!!!!!!!

      PRANAV replied 6 years, 10 months ago 2 Members · 1 Reply
      • Login
      • Retrieve
      • Salesforce Licenses
      • Salesforce User Licenses
      • User Group
      • User in Salesforce
      • User License
    • 1 Reply
    • PRANAV

      Member
      June 3, 2019 at 2:38 PM

      Hi
      There are many reasons if you can't get your desired output from the provided code:
      1) You have to give the License name correctly
      2) The user data you want to query must check it an active user as you added that filter in your query
      3) You have to check the usertype also
      For the best solution, you can first run the query in the query editor then add that query in the code for the desired output.

    Log In to reply.

    • Public
    • All Members
    • My Connections
    • Only Me
    • Public
    • All Members
    • My Connections
    • Only Me
    • Public
    • All Members
    • My Connections
    • Only Me

    application solution

    Popular Salesforce Blogs

    The Ultimate Guide to Setting Up a Salesforce Multi-language Platform for a Global Audience

    The Ultimate Guide to Setting Up a Salesforce Multi-language Platform for a Global Audience

    Blog in Salesforce

    Many businesses have thrived in the globalized market, especially small-medium enterprises. According to OECD, 95% of companies are SMEs, accounting for 60-70% of employment in…

    Beta Testers, CRM, Customer Satisfaction, Increase Revenue, Localization Strategy
    Mitesh Mar 29, 2023
    1,432  Views

    Decoding Salesforce Summer 16 Release Notes

    Blog in Lightning

    It has been 2 months since the latest major salesforce release, the spring 2016 edition. The new release again aimed at bridging the gaps left…

    Email Service, Lightning Component, Lightning Experience, Microsoft Office, Salesforce Release
    Obivan Jul 6, 2016
    2,942  Views
    Salesforce Editions Comparison

    Salesforce Editions Comparison: Choosing the Right Edition for your Business.

    Blog in Others

    Salesforce offers multiple CRM editions like the Essentials, Professional, Enterprise and Unlimited – each of these Salesforce editions geared towards specific business needs. Designed for small…

    Campaign Management, Case Management, Contact Management in Salesforce, Dashboards in Salesforce, Force.com
    LevelShift (formerly DemandBlue) Aug 9, 2018
    5,408  Views

    Popular Salesforce Videos

    Difference between Profile and Roles in Salesforce

    Difference between Profile and Roles in Salesforce

    Video in Salesforce Admin

    Learn about the difference between Profile and Roles? Watch this video and do let us know if you have any questions or concerns.

    Salesforce Training, Salesforce Tutorial, Salesforce Online Training, Salesforce Certification, Profiles In Salesforce
    CRS Mar 10, 2022
    2,219  Views
    How to Automate Business Processes in Salesforce CRM | Salesforce Flow Explained

    How to Automate Business Processes in Salesforce CRM | Salesforce Flow Explained

    Video in Salesforce Admin

    Want to streamline your business processes without diving into complex coding? In this video, Kirill, an AQA engineer and certified Process Automation Professional at ENWAY,…

    Salesforce Flow, Salesforce Flow Builder, Flow Builder, Salesforce Flows, Schedule-Triggered Flow
    ENWAY Sep 5, 2025
    112  Views
    How the Salesforce Ecosystem Helped My Career

    How the Salesforce Ecosystem Helped My Career

    Video in Salesforce Stories

    Welcome back to 100DaysofTrailhead.com! Your involvement in the Salesforce Ecosystem can be a great boost to your career. In this video, Eric talks about the…

    Salesforce Tutorial, Salesforce Jobs, Salesforce Community, Salesforce Trailhead, Salesforce Developers
    Pooja Oct 1, 2021
    1,418  Views
    Footer Forcetalks logo

    support@forcetalks.com

    • twitterx

    Quick Links

    Advertise with Us

    Salesforce® Articles

    Dreamforce 2023

    Top Salesforce® Bloggers 2023

    Top Salesforce Consultants

    Get Listed

    Company

    Contact Us

    About Us

    Privacy Policy

    Terms & Conditions

    InsightHub

    Salesforce Blogs

    Salesforce Videos

    Salesforce Groups

    Salesforce Jobs

    © 2026 - Forcetalks ● All Rights Reserved

    Salesforce® is a trademark of Salesforce® Inc. No claim is made to the exclusive right to use “Salesforce”. Any services offered within the Forcetalks website/app are not sponsored or endorsed by Salesforce®.

    Try AuditMyCRM - It is a Salesforce CRM Audit tool which comprehensively scans your Salesforce org and gives you the list of errors or warnings you need to take care of.
    We use cookies to enhance your browsing experience. Please see our privacy policy if you'd like more information on our use of cookies.