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

    Salesforce Summer ’18 Release - Key Points

    Blog in Salesforce Releases

    Three times per year, Salesforce release a new version of their products, full of new and exciting features. The first and second weekend of June…

    Salesforce Consultant, Salesforce Consulting, Salesforce Development, Salesforce Partner, salesforce summer release
    KeyNode Jun 18, 2018
    4,560  Views
    Salesforce Partners

    2020 Branding Guidelines for Partners in the Salesforce Ecosystem

    Blog in AppExchange, Salesforce

    The Salesforce Partner Program gives the opportunity to its partners to build and grow successful businesses while delivering customer success. With this program, Independent Software…

    AppExchange, Independent Software Vendors, ISVs, Salesforce, Salesforce Consulting Companies
    Algoworks Apr 14, 2020
    2,725  Views

    Seven Vital Reasons to Choose Salesforce for the Manufacturing

    Blog in Salesforce

    As the business world evolves, the importance of a robust CRM becomes evident. This powerful tool serves as your guiding beacon, skillfully navigating the ever-shifting…

    Automation, Business Processes, CRM, Customer Information, Customer Relationship
    DemandBlue Dec 27, 2023
    1,258  Views

    Popular Salesforce Videos

    Accelerate Revenue by Simplifying Partner Data Exchange

    Video in Data

    Adeptia Webinar :: Self-service approach to set up secured B2B data exchanges. Allowing IT to focus on governance for ensuring compliance, security, and control.Reducing IT…

    Data Integration, B2B Integration
    Prince Mar 22, 2018
    2,039  Views
    Success from Anywhere with Salesforce EMEA Leaders

    Success from Anywhere with Salesforce EMEA Leaders

    Video in Salesforce Stories

    Watch this video to learn about Success from Anywhere with Salesforce EMEA Leaders. Do let us know your opinions in the comment section.

    Salesforce Training, Salesforce Tutorial, salesforce, Salesforce Video, Salesforce Learning
    Nauman Oct 19, 2021
    1,740  Views
    Time-based Workflow Rules In Salesforce | Salesforce Tutorial

    Time-based Workflow Rules In Salesforce | Salesforce Tutorial

    Video in Salesforce Training

    Learn all about time-based workflow rules in Salesforce. This tutorial will cover the following points - 1. Create A Workflow Rule Learn how a workflow…

    Salesforce Training, Salesforce Tutorial, salesforce, Salesforce Video, Salesforce Learning
    Algoworks Feb 11, 2021
    3,454  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.