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, 6 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

    How to Boost a 21st Century Mobile Workforce for Non-profits

    Blog in Others

    How do mobile technologies affect non-profit organizations? Do they affect them at all? Let’s find out! Imagine, one day, your non-profit will change the world…

    Application, CRM, custom, fundraising, mobile
    Barbora Jun 22, 2018
    2,689  Views

    Top Sales Challenges in 2023 Which Salesforce Sales Cloud Can Solve

    Blog in Salesforce

    There’s no denying the fact that a sales job is full of challenges. Sales managers are constantly on the lookout for ways to optimize their…

    Assessment, Automated template, Automation, Bad Hiring, Boosting business ROI
    Damco Jul 25, 2023
    1,783  Views

    Salesforce and Google Expand their Partnership

    Blog in Salesforce Ecosystem

    Google Workspace and Salesforce announced a partnership extension. Companies are going to enhance their AI capabilities. Salesforce and Google announced their teaming up at the…

    Artificial Intelligence, Assign Tasks, Better Business Outcomes, Einstein Copilot, Enhance Productivity
    Sparkybit Dec 7, 2023
    873  Views

    Popular Salesforce Videos

    Salesforce to Twilio Integration Using MuleSoft | SFDC

    Salesforce to Twilio Integration Using MuleSoft | SFDC

    Video in Salesforce Integration

    Take a look at how Twilio integration with Salesforce is done using MuleSoft. This tutorial will cover the following points - 1. Introduction Learn how…

    Salesforce Training, Salesforce Tutorial, salesforce, SFDC, Salesforce Video
    Algoworks Mar 12, 2021
    2,814  Views
    ChartJs Implementation In Salesforce

    ChartJs Implementation In Salesforce

    Video in Others, Lightning

    This was my very first lightning web component I had made on my own. Thought of sharing it 🙂 This component basically shows the no.…

    Salesforce Training, Salesforce Lightning, salesforce, Salesforce Video, Salesforce Learning
    Hitesh Garg?️ Oct 19, 2020
    2,095  Views
    Power of Personal Brand | The Shrey Sharma Show | Salesforce

    Power of Personal Brand | The Shrey Sharma Show | Salesforce

    Video in Salesforce Training

    Shrey is a Chief Executive Officer at Cyntexa, a SILVER Salesforce Consulting Partner in the USA, UK, UAE, Australia, Singapore & India, having a vibrant…

    Salesforce Training, Salesforce Certification, Salesforce Developer, salesforce, Salesforce Course
    S2 Nov 29, 2021
    1,601  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

    © 2025 - 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.