I need to fetch the currently logged in user id, username, email, first name, last name from SFDC using the JavaScript function.

I have VF page created on which I wrote a script tag, in which I need to fetch the logged in user information using only JavaScript functions.

I don't want to fetch using VF code, I only need pure Javascript code wirtten on VF page.

How is it possible to do this?

closed as unclear what you're asking by Derek F, Vijay Ganji, Pranay Jaiswal, glls, Mohith Shrivastava Jul 5 at 15:45

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    Please do not post "urgent" requests for code on SFSE. That's not how this site works. Please take some time to go through our Tour and read How to Ask, then post a question that shows what you've done so far and poses a single, specific question the community can help you with. – David Reed Jul 4 at 14:12
  • 2
    I've removed these phrases from your question, but I would strongly encourage you to provide some explanation of your use case and what you've done so far. – David Reed Jul 4 at 14:15
  • Also, please correct your question's terminology. Right now, it sounds like you want to do something in VF but you don't want to do it in VF, which makes no sense. What exactly are you trying to accomplish? What restrictions are you placing on viable solutions? The better worded your question is, the better we can assist you. – sfdcfox Jul 4 at 15:53

You can use Javascript remoting directly call apex method to get loggedin user details directly from Javascript.


public with sharing class MyController {
    public static User getLoginUserDetails()
        return [SELECT Id, Name FROM User WHERE Id = :UserInfo.getUserId()];


<apex:page controller="MyController">
    <script >
        function getUserDetails() {


                function(result, event){

    </script >
  • 1
    Thanks @santanu, this has worked and met my requirement – Nalla Dileep Jul 6 at 14:00

Not the answer you're looking for? Browse other questions tagged or ask your own question.