You need to sign in to do that
Don't have an account?
Very strange SOQL / Eclipse error
Hi,
I'm getting some strange behaviour using Eclipse with a SOQL query in a class. I'm using the schema section to test the query out and just for sanity, building the query using the checkboxes to ensure the relationships are correct.
I'm trying to query the Lead object and show the Lead Owner's Division.
To do this, you join with User. The field "Division" is a standard Salesforce.com field, as is Username, Lastname,Firstname, Fullname, Street, City, State, Email, Phone, and so on.
The following example queries work:
Select l.Owner.Name, l.OwnerId, l.Company From Lead l
Select l.Owner.Username, l.OwnerId, l.Company From Lead l
Select l.Owner.Phone, l.OwnerId, l.Company From Lead l
Select l.Owner.Email, l.OwnerId, l.Company From Lead l
Select l.Owner.ProfileId, l.OwnerId, l.Company From Lead l
These are some that don't work:
Select l.Owner.Division, l.OwnerId, l.Company From Lead l
Select l.Owner.Country, l.OwnerId, l.Company From Lead l
Select l.Owner.City, l.OwnerId, l.Company From Lead l
Select l.Owner.Department, l.OwnerId, l.Company From Lead l
The error message:
Unable to open Schema Browser. Reason: INVALID_FIELD - Select l.Owner.Division,l.OwnerId,l.Company from Lead l ^ ERROR at Row:1:Column:8 No such column 'Division' on entity 'Name'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.
If they're all non-custom fields on a non-custom object, the relationship name should work?
Is there anything I'm missing?
Hey
I'm not a 'lead' expert, but if I look at that field within the browser it says this,
Data Type: Lookup(User,Queue)
So this field seems to be some combination of those two. It is a bit curious to me, but I work almost exclusively with the custom stuff, and you can't create a lookup by combining two objects. The only thing I can suggest is getting your userId value and fetching the user with the values you get.
Good luck,
Wes
The SOQL relationship "Owner" is working properly -- at least part of the time as per the above examples.
I'm able to pull "User.Username" for example. It doesn't work if I want to pull "User.Division" and that seems strange to me.
Why would a relationship pull some fields and not others? I've written loads of these SOQL joins into APEX code and I've never seen this. Hopefully someone else has?
I'm having this same issue but with Events. I can pull the Id and name from the WhatId record, but any other fields (whether custom or standard) I get the message about it not being a valid column on entity 'Name'
Its because its a polymorphic FK, the fk can point to many different types of objects, in that case you can only select a common subset of fields (these are defined in the name entity). see the section on polymorphic FKs in the SOQL-R docs.