3

Been stuck on this for a while now, trying to write a query against LoginEvent that pulls in some User data so I can eventually craft some custom alerting. Getting an error on a specific field in the User object, even though I'm able to query other fields from that object and even dot hop through it.

SELECT EventDate, Application, LoginType, LoginUrl, Platform, Status, Username, User.Profile.Name, User.Title, User.LocNum__c FROM LoginEvent

User.Profile.Name, User.Title both come through fine. And I can query LocNum__c directly from the User object without an issue so it's not an access issue. Not sure if it's because it's a custom field or not but what's throwing me is the return of 'Name' even though I have access to the field and the only time I've seen it return that is when there's a polymorphic parenting.

1
  • I just realized you asked about LoginEvent, not LoginHistory. It'll take me a moment to check this out, unless someone beats me to it. I suspect some kind of bug is afoot, or maybe it's an intentional design.
    – sfdcfox
    Dec 23, 2021 at 19:11

1 Answer 1

1

This is simply as per design. You cannot reference custom field and few other standard fields of user object via relationship query.

This also applies for custom objects with owner field. For custom objects though you can simply create formula fields, however here that is not an option.

You can collect all the UserIds and then simply query the user object with the custom fields you need.

5
  • Can you add reference to the documentation for this please?
    – Phil W
    Dec 23, 2021 at 20:13
  • Can’t share internal docs :) Hopefully we can get this documented in public docs. Dec 23, 2021 at 21:00
  • BTW, the Owner thing... isn't that just a matter of using the appropriate type check too to handle the polymorphism scenario?
    – Phil W
    Dec 23, 2021 at 22:15
  • Ya TYPE OF can also solve it. I do have to still try and see if it works with custom field as well. Dec 23, 2021 at 22:35
  • If I can't upquery from LoginEvent, can I subselect by hitting User? I'm trying to figure out what the relationship name is but not finding it after dumping the WSDL. I'm not sure what the DescribeSObject method is to get the relationship names but I feel like there probably is one. Everything I'm trying is throwing a "Did not understand the relationship" in the subselect. // SELECT Profile.Name, Title, LocNum__c, (SELECT EventDate, Application, LoginType, LoginUrl, Platform, Status, Username FROM LoginEvents) FROM User Jan 4, 2022 at 14:15

You must log in to answer this question.

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