function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
kevincar64kevincar64 

SOQL trouble

I'm missing something fundamental - I need to get the Owner, Number of Leads, and the role description of the lead owners on a single  SOQL statement.  I'm trying the following:

 

SELECT Lead.Owner.Alias,Owner.Id, Lead.Owner.UserRoleId,
Lead.Owner.UserRoleId.Name,  Count(Id)
 FROM Lead  
 WHERE Lead.Owner.IsActive = TRUE
 AND IsUnreadByOwner = True
 GROUP BY Lead.Owner.Alias, Lead.Owner.Id, Lead.Owner.UserRoleId, Lead.Owner.UserRoleId.Name
 HAVING Count(Id) < 25
 ORDER BY Lead.Owner.Alias ASC
LIMIT 45

 ...but I get

INVALID_FIELD:
ERROR at Row:2:Column:1 Didn't understand relationship 'UserRoleId' in field path.

 If I don't try to return "Lead.Owner.UserRoleId.Name" it works fine... which I'm thinking is because I'm mixing child-to-parent and parent-to-child, but I thought that since I already grabbed Lead.Owner.UserRoleId successfully I could also get the name.

 Is there any way to do this?

Thanks in advance

 KC64


Best Answer chosen by Admin (Salesforce Developers) 
NiketNiket

Hi ,

 

try this query :

 

SELECT Lead.Owner.Alias,Owner.Id, Lead.Owner.UserRoleId,
Lead.Owner.UserRole.Name, Count(Id)
FROM Lead
WHERE Lead.Owner.IsActive = TRUE
AND IsUnreadByOwner = True
GROUP BY Lead.Owner.Alias, Lead.Owner.Id, Lead.Owner.UserRoleId, Lead.Owner.UserRole.Name
HAVING Count(Id) < 25
ORDER BY Lead.Owner.Alias ASC
LIMIT 45

 

Please mark it as the solution if it answers your question so that others can also take benifit. 

 

Ckeck My Blog

All Answers

NiketNiket

Hi ,

 

try this query :

 

SELECT Lead.Owner.Alias,Owner.Id, Lead.Owner.UserRoleId,
Lead.Owner.UserRole.Name, Count(Id)
FROM Lead
WHERE Lead.Owner.IsActive = TRUE
AND IsUnreadByOwner = True
GROUP BY Lead.Owner.Alias, Lead.Owner.Id, Lead.Owner.UserRoleId, Lead.Owner.UserRole.Name
HAVING Count(Id) < 25
ORDER BY Lead.Owner.Alias ASC
LIMIT 45

 

Please mark it as the solution if it answers your question so that others can also take benifit. 

 

Ckeck My Blog

This was selected as the best answer
kevincar64kevincar64

Thanks again, Niket!

 

Sorry for the cross-posting, I just didn't know which forum would get a resonse.

Double-thanks for posting the solution twice :-)

 

KC64

NiketNiket

No problem Kevin. I am happy to help ..