Skip to main content
Bumped by Community user
Bumped by Community user
Bumped by Community user
Bumped by Community user
added 103 characters in body; edited tags
Source Link
Samuel De Rycke
  • 9.6k
  • 8
  • 46
  • 73

I seem to have run in to a SOQL error that I'm hoping someone has solved before.

I am creating a dashboard for UserLogins using the LoginHistory object (https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_loginhistory.htmLoginHistory object)

The query I am trying to run is:

SELECT COUNT_DISTINCT(userid) agg FROM loginhistory WHERE logintime = THIS_MONTH AND userid IN ('id1', 'id2...)

SELECT COUNT_DISTINCT(userid) agg 
FROM loginhistory 
WHERE logintime = THIS_MONTH 
AND userid IN ('id1', 'id2', ...)

When I run the query I get back this agg result: [ { "attributes" : { "type" : "AggregateResult" }, "agg" : 1 } ]

[ {
  "attributes" : {
    "type" : "AggregateResult"
  },
  "agg" : 1
} ]

What I need is the number of distinct logins within the time frame, however when I add a GROUP BY UserID salesforce errors: "Grouped field should not be aggregated: UserId"

"Grouped field should not be aggregated: UserId"

Query: SELECT userid,COUNT_DISTINCT(userid) agg FROM loginhistory WHERE logintime = TODAY AND userid IN ('id1','id1') Group By userid

SELECT userid,COUNT_DISTINCT(userid) agg 
FROM loginhistory 
WHERE logintime = TODAY 
AND userid IN ('id1','id1') 
GROUP BY userid

I seem to have run in to a SOQL error that I'm hoping someone has solved before.

I am creating a dashboard for UserLogins using the LoginHistory object (https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_loginhistory.htm)

The query I am trying to run is:

SELECT COUNT_DISTINCT(userid) agg FROM loginhistory WHERE logintime = THIS_MONTH AND userid IN ('id1', 'id2...)

When I run the query I get back this agg result: [ { "attributes" : { "type" : "AggregateResult" }, "agg" : 1 } ]

What I need is the number of distinct logins within the time frame, however when I add a GROUP BY UserID salesforce errors: "Grouped field should not be aggregated: UserId"

Query: SELECT userid,COUNT_DISTINCT(userid) agg FROM loginhistory WHERE logintime = TODAY AND userid IN ('id1','id1') Group By userid

I seem to have run in to a SOQL error that I'm hoping someone has solved before.

I am creating a dashboard for UserLogins using the LoginHistory object

The query I am trying to run is:

SELECT COUNT_DISTINCT(userid) agg 
FROM loginhistory 
WHERE logintime = THIS_MONTH 
AND userid IN ('id1', 'id2', ...)

When I run the query I get back this agg result:

[ {
  "attributes" : {
    "type" : "AggregateResult"
  },
  "agg" : 1
} ]

What I need is the number of distinct logins within the time frame, however when I add a GROUP BY UserID salesforce errors:

"Grouped field should not be aggregated: UserId"

Query:

SELECT userid,COUNT_DISTINCT(userid) agg 
FROM loginhistory 
WHERE logintime = TODAY 
AND userid IN ('id1','id1') 
GROUP BY userid
Source Link
ChrisBland
  • 317
  • 2
  • 7

Querying distinct logins using LoginHistory and COUNT_DISTINCT

I seem to have run in to a SOQL error that I'm hoping someone has solved before.

I am creating a dashboard for UserLogins using the LoginHistory object (https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_objects_loginhistory.htm)

The query I am trying to run is:

SELECT COUNT_DISTINCT(userid) agg FROM loginhistory WHERE logintime = THIS_MONTH AND userid IN ('id1', 'id2...)

When I run the query I get back this agg result: [ { "attributes" : { "type" : "AggregateResult" }, "agg" : 1 } ]

What I need is the number of distinct logins within the time frame, however when I add a GROUP BY UserID salesforce errors: "Grouped field should not be aggregated: UserId"

Query: SELECT userid,COUNT_DISTINCT(userid) agg FROM loginhistory WHERE logintime = TODAY AND userid IN ('id1','id1') Group By userid