I have one query as below:

select id,functional_system_user__c,
  from user where id='ABC'

Another query is :

select id,isfrozen,userid from userlogin where userid ='ABC'

I wanted isfrozen field to be included in 1st SOQL.I have written below query and i am getting error saying invalid relationship.

select id, functional_system_user__c, Test_Created_Date__c,  
       Test_Login_Date__c, isactive, Reactivation_Date__c, email,  
       (select isfrozen from userlogin ) 
  from user where id='ABC'

Id of 1st SOQL is equal to userid of 2nd SOQL.

  • you can't subquery userlogin seems like limitation.. You can check in eclipse's salesforce schema If we can subquery or not..
    – Ratan Paul
    Jan 27, 2016 at 11:16
  • 1
    I have checked on WorkBench, and it seems that UserLogin's field UserId is not really a relationship, only value. So you have to do 2 soql
    – kurunve
    Jan 27, 2016 at 11:17
  • But userid of userlogin table is same as id of user table.So is it possible to write.
    – Jack vardy
    Jan 27, 2016 at 11:20
  • as well as OwnerId on account is also the same as id of user id, you should be able to query all user accounts by (select Id,(Select Id From Accounts) From User). But you can not. Not every salesforce relation behave like custom field lookup/master-detail.
    – kurunve
    Jan 27, 2016 at 16:32
  • 1
    Can you post these comments as an answer, @kurunve? Jan 27, 2016 at 19:24

1 Answer 1


It does not seem possible to subquery this child relationship. I ran the following:

for (ChildRelationship relationship : SObjectType.User.getChildRelationships())
    if (relationship.getChildSObject() == UserLogin.sObjectType)
        system.debug(relationship.getField() + ' - ' + relationship.getRelationshipName());

The results I got were:

USER_DEBUG [5]|DEBUG|LastModifiedById - null
USER_DEBUG [5]|DEBUG|UserId - null

This means that while the relationship is there, it does not have a name you can use.

Contrast this with, for example, an attempt to subquery AccountTeamMember records. If I change the SObjectType I am looking for above, I get

USER_DEBUG [5]|DEBUG|CreatedById - null
USER_DEBUG [5]|DEBUG|LastModifiedById - null
USER_DEBUG [5]|DEBUG|UserId - AccountTeams

So I cannot subquery AccountTeamMember records based on LastModifiedById from a User query, but I can merge in the relationship name to look at any matches on UserId:

SELECT (SELECT Account.Name FROM AccountTeams) FROM User

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.