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

    Top Mistakes to Look Out for While Hiring Salesforce Professionals

    Blog in Salesforce

    With Salesforce becoming the top CRM product globally, the need for Salesforce implementation and administration in organizations is increasing every day. This has resulted in…

    Applications, Automate Processes, Automation, budget, Business Practices
    Carol Jun 7, 2023
    1,806  Views
    Data Quality Analysis

    Data Quality Analysis Dashboard App in Salesforce

    Blog in AppExchange, Data

    As you all know about the importance of Data Integration in Salesforce, we should understand that before Data integration, Data Quality analysis and management are…

    Bad Data Quality, Business Goals, Business Objectives, Business Productivity, Business Revenue
    Melonleaf Mar 24, 2022
    7,934  Views

    A Nonprofit's Success with Salesforce

    Blog in Salesforce Implementation

    Case Study: Nonprofit Organization Leverages Salesforce for Growth Organization: The Community Foundation   Challenge: The Community Foundation struggled to manage donor relationships, track donations effectively, and…

    Data-Driven Decision-Making, Nonprofit Cloud Solutions, Nonprofit Collaboration Tools, Nonprofit CRM Best Practices, Nonprofit CRM Customization
    Cloudy Sep 11, 2024
    532  Views

    Popular Salesforce Videos

    Pardot Marketing Automation Tools Overview Webinar

    Pardot Marketing Automation Tools Overview Webinar

    Video in Salesforce Automation

    Are you looking to take your Salesforce Marketing Automation to the next level? Learn how to build successful lead nurturing campaigns that empower your sales team…

    Salesforce Development, Marketing Automation, Salesforce Marketing Cloud, Salesforce CRM, Salesforce Tools
    Victoria Dec 3, 2018
    2,229  Views
    Dynamic Forms in Salesforce

    Dynamic Forms in Salesforce

    Video in Salesforce Training

    Hello Everyone, in this video, we will talk about what the dynamic form is and how to work with the dynamic form in Salesforce. Watch…

    Salesforce Training, Salesforce Tutorial, salesforce, Salesforce Video, Salesforce Learning
    Rupal Kakkar Jun 18, 2021
    2,127  Views
    Enhance Not Divest your Investment in Salesforce

    Enhance Not Divest your Investment in Salesforce

    Video in Others

    Here in a short Video Blog, Ian Moyse, Natterbox Sales Director and Sales Director of the year winner (Institute of Sales Management) talks to how…

    Salesforce Tools, Salesforce Data, Sales Cloud, Salesforce VIdeos, Service Cloud
    Ian Moyse Feb 10, 2020
    1,905  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.