You need to sign in to do that
Don't have an account?
louisa barrett 7
SOQL to return user id and list of custom object
Hi,
I would like to return a user ID and a list of custom objects that the user is the owner of using an inner select, but I don't know where to find the child relationship name for the custom object.
example:
List<User> owners = [SELECT ID, Name,
(SELECT ID, Name, OwnerID, Month_Number__c
FROM Custom_Object__c)
FROM User
WHERE OwnerID IN : ownerIDs];
I basically want to end up with a map of <ID, List<Custom_Object__c>>(), where the ID is the user ID and the list is all the custom object records that the user is the owner of.
Normally I would just look on the object and get the child relationship name from there, but the user object does not show it's related objects.
Is this query possible from the user table?
Thanks
I would like to return a user ID and a list of custom objects that the user is the owner of using an inner select, but I don't know where to find the child relationship name for the custom object.
example:
List<User> owners = [SELECT ID, Name,
(SELECT ID, Name, OwnerID, Month_Number__c
FROM Custom_Object__c)
FROM User
WHERE OwnerID IN : ownerIDs];
I basically want to end up with a map of <ID, List<Custom_Object__c>>(), where the ID is the user ID and the list is all the custom object records that the user is the owner of.
Normally I would just look on the object and get the child relationship name from there, but the user object does not show it's related objects.
Is this query possible from the user table?
Thanks
List<User> owners = [SELECT ID, Name, (SELECT ID, Name, OwnerID, Closed_Amount__c, Month_Number__c FROM Sales_Target__c) FROM User
WHERE OwnerID IN : ownerIDs];
The error I get is that the relationship Sales_Targets__c is not understood, which I understand why, but I don't know where to get the relationship name from as it is not listed on the user object.
The custom object is named Sales_Target__c, with a plural name of Sales_Targets__c.
The ownerID field is the standard field that is created on a custom object.
Many thanks
On the other hand, you can get all the Child SObject by filtering if (C.getField().getDescribe().getName() == 'OwnerId') {