You need to sign in to do that
Don't have an account?

Using SOQL to access lookup relationships in custom objects.
I'm trying to access a custom lookup relationship field using SOQL and I was testing different queries in the FORCE IDE for Eclipse. I'm not getting the result I want and I wanted know how I can get SOQL to return the
actual field value.
SELECT custom_objectBLookup__r.CustomField__c
FROM
custom_objectA__c
and I get this
custom_objectB__c
but instead I want to access the actual CustomField value
"value"
Well, to be clear, if you have something like
ObjA__c a = [select ObjB__r.FieldB, Id from ObjA__c limit 1];
Then you'd still have to reference your field as
a.ObjB__r.FieldB
So there's one level of indirection there. In that sense the IDE is displaying the information strictly correctly, showing the one level of indirection, but it can be misleading to make you think that you have to do some crazy machinations to get to the data itself when in fact it's quite simple.
Well I'm still not getting the actual value even when I try it in Apex using the System Log so for example if I do something like this.
List<ObjA__c> aa = [SELECT ObjA__c.ObjB__r.FirstName__c FROM ObjA__c];
for(ObjA__c aaa: aa)
{
System.debug(aaa);
}
I still get the following:
AnonymousBlock: line 5, column 6: ObjA__c:{ObjB__c=############, Id=################}
yeah I agree it should be quite simple but its not and I'm not sure what to do with it.