Toggle Side Panel

  • Blogs
  • 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
  • Contact Us
  • Discussions
More options
    Sign in Sign up
    • Blogs
    • 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
    • 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 7 years, 2 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

    Popular Salesforce Blogs

    Salesforce Reshapes AI Pricing Through Agentforce’s Pay-for-Resolution Approach

    Blog in Salesforce

    Salesforce launched Agentforce less than two years ago as a platform designed to help businesses build, deploy, and manage AI agents. Since then, organizations have…

    Agentforce
    Cloudmetic Jul 24, 2026
    59  Views
    The Most Important Pardot Automation Rules You Need to Know

    The Most Important Pardot Automation Rules You Need to Know in 2023

    Blog in Salesforce

    Pardot is a powerful marketing automation platform that enables businesses to streamline their lead generation and nurturing efforts. One of the key features of Pardot…

    Lead generation, Lead Nurturing, Marketers, Marketing and Sales Teams, Marketing Automation
    Mohit Kumar Feb 6, 2023
    2,955  Views
    SALES PATH-Your Company’s Sales Processes in Lightning Experience

    SALES PATH: Your Company’s Sales Processes in Lightning Experience

    Blog in Lightning, Salesforce, Salesforce Implementation

    Sales Path is a great feature that Salesforce is made available for Lightning Experience only. This tool is designed to guide your sales reps through…

    Lightning, Saleforce, Sales Path, Salesforce Customization, Salesforce1
    PRANAV Jan 5, 2018
    26,827  Views

    Popular Salesforce Videos

    Kanban View and Personalisation | Salesforce Training

    Kanban View and Personalisation | Salesforce Training

    Video in Others, Salesforce Training

    In this short video, we will show you the Kanban view in Salesforce Lightning and how it can be personalized. Check out this amazing and…

    Salesforce Training, Salesforce Tutorial, Salesforce Lightning, Salesforce Video, Salesforce Learning
    Stimulus Consulting Oct 6, 2020
    2,659  Views
    Using Lambdas to Overcome Salesforce Governor Limits

    Using Lambdas to Overcome Salesforce Governor Limits

    Video in Others

    Salesforce is a great CRM product, but it has some limitations that can prove troublesome depending on the situation. Since each org has to share…

    Salesforce Consulting, support, Development, Integrations, Governor Limits
    DB Sep 10, 2024
    674  Views
    Adding an Email Service Channel with Email-to-Case | Salesforce Tutorial

    Adding an Email Service Channel with Email-to-Case | Salesforce Tutorial

    Video in Salesforce Training, Salesforce Admin

    Learn how to add an email service channel with Email-to-Case. This feature will enable you to resolve and correspond with customer inquiries via email without…

    Salesforce Training, Salesforce Tutorial, salesforce, Salesforce Video, email to case
    SkyPlanner Nov 28, 2023
    1,212  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®.

    We use cookies to enhance your browsing experience. Please see our privacy policy if you'd like more information on our use of cookies.