1

.rTable { display: table; }

<script type="text/javascript">
var __sfdcSessionId = '{!GETSESSIONID()}';
</script>
<script src="../../soap/ajax/37.0/connection.js"
      type="text/javascript"></script>
<script type="text/javascript">     window.onload = setupPage;
function setupPage() {

  var state = { //state that you need when the callback is called
      output : document.getElementById("output"),
      startTime : new Date().getTime()};

  var callback = {
      onSuccess: layoutResults,

      onFailure: queryFailed,
      source: state};

  sforce.connection.query(
      "Select UsersId, UserType,IsCurrent,users.name From AuthSession ",
       callback);

}

function queryFailed(error, source) { source.output.innerHTML = "An error has occurred: " + error; }

function layoutResults(queryResult, source) { if (queryResult.size > 0) { var records = queryResult.getArray('records'); for (var i = 0; i < records.length; i++) { var user = records[i];

        var tr = document.createElement("tr");
        tr.innerHTML = '<td>' + user.UsersId + '</td>' + '<td>' + user.UserType  + '</td>'+ '<td>' + user.IsCurrent + '</td>';
        document.getElementById("myTable").appendChild(tr);         
    }
    source.output.innerHTML = output;
}

}

<html>
Id Name iscurrent

i tried to get all the logged in users,,am getting ids ,i also want to display the names.need help to meet this.thanks in advance

1 Answer 1

3

You can use the following query instead:

select name from user where id in 
    (select usersid from authsession where iscurrent = true)

This will give you a de-duplicated list of all the users with current sessions by name. You can also select any of the other usual User fields.

Alternatively, UsersId is a normal relationship field, so you can also do:

select users.name from authsession where iscurrent = true
4
  • Unfortunate choice of API Name, that. UsersId...
    – Adrian Larson
    Commented Jul 1, 2016 at 6:46
  • select users.name from authsession where iscurrent = true i,used this,,i want to add this to <tr>,,,see my updated code
    – Satya
    Commented Jul 1, 2016 at 8:03
  • @sahisfdc var user = records[i]; ... + user.Users.Name +; make sure you check the capitalization of the variables.
    – sfdcfox
    Commented Jul 1, 2016 at 8:05
  • when i run this query it only returns the running user (myself) unless I remove IsCurrent. I have tested multiple times. Can you confirm that it returns all logged in users for you? I have an open question for this here
    – gorav
    Commented Jun 11, 2020 at 11:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .