1
<apex:page showHeader="false">
    <style type="text/css">
        .rTable {
            display: table;
        }
    </style>
    <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 where IsCurrent= true ",
                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>' + '<td>' + user.Users.Name + '</td>';
                    document.getElementById("myTable").appendChild(tr);
                }
                source.output.innerHTML = output;
            }
        }
    </script>
    <html>
    <table id="myTable">
        <!-- Header -->
        <tr>
            <td> Id </td>
            <td> Name </td>
            <td> iscurrent</td>
            <td> username</td>
        </tr>
    </table>
    </html>
</apex:page>

currently i had logged in 2 users, one is admin in chrome another is slead user in internet browser, But my code show only one user logged in, i want to get both the users,please ,,,,"i want a query that show shows all logged in users.(different browsers r different systems)need your help,thanks in advance

3
  • query returns 1 user both for admin and simple user? Jul 1 '16 at 12:11
  • my code returns 1 ..i.e..admin is only true ,,not showing the second user.
    – Satya
    Jul 4 '16 at 5:30
  • because of i logged in users,it has to show two users active means,isCurrent=true.
    – Satya
    Jul 4 '16 at 5:30
0

Use query without IsCurrent = true to see all sessions

https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_authsession.htm

Description If true, the session is a member of the user’s current session family. This field is available in API version 37.0 and later.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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