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
Vinnie BVinnie B 

Trying to do a simple join on a custom object

I can run the following simple query on the standard Account and Contacts object to include values from the parent object when querying the child object.

 

select firstName, lastName, Account.Name
  from Contact
  where firstName like 'Vinn%'

 

However, when I try to do this on a custom object I created, Custom_Account__c, I can't get it to work at all.  I set up the lookup field on Contact to have the same relationship as it does with the regular Account object (parent/child).

 

I tried the following query and many other permutations including putting the relationship name (Contacts) in place of Custom_Account__c, doing this with and without "__r" appended to it.

 

select firstName, lastName, Custom_Account__c.Number_Field__c
  from Contact
  where firstName like 'Vinn%'

 

I tried all sorts of variations but I keep getting the error:

 

"Didn't understand relationship 'Custom_Account__c' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names."

 

I don't understand why I can't simply reference the fields in a custom parent object as I do with a standard parent object.

 

Thanks!

Best Answer chosen by Admin (Salesforce Developers) 
GlynAGlynA

Assuming Custom_Account__c is a lookup field on Contact, then

 

select firstName, lastName, Custom_Account__r.Number_Field__c
  from Contact
  where firstName like 'Vinn%'

 

should work.  Is this not the case?

 

-Glyn

All Answers

GlynAGlynA

Assuming Custom_Account__c is a lookup field on Contact, then

 

select firstName, lastName, Custom_Account__r.Number_Field__c
  from Contact
  where firstName like 'Vinn%'

 

should work.  Is this not the case?

 

-Glyn

This was selected as the best answer
Vinnie BVinnie B

Wow!  That was easy.  I tried it on the more complicated query I was actually trying to do and it worked there as well.  I did try all sorts of permutations and am suprised I didn't do that one.  :)

 

THANKS!!