1

I am trying to write a SOQL query to pull out a number of items from 3 Objects - Contact, Account and Case.

I have the following code:

SELECT id, accountid, contactid, contact.primary_contact__c FROM case WHERE contact.Phone = '+6491234567' order by contact.primary_contact__c asc

Which returns a result if the Contact has an open Case related to them.

However, I'm trying to do an equivalent of a SQL Join - whereby I get NULL values and pulling from the Contact object:

SELECT id, accountid, primary_contact__c, (select id from case) FROM contact WHERE Phone = '+6491234567' order by primary_contact__c asc

(So the query will always return the ID of the Contact, the Account ID, etc. and if there is a case assigned against that contact, the case ID)

However the second query does not work - I know that the Relationships exist (otherwise the first query would not work) however, I'm not sure what I'm doing wrong here.

3

This is because the child relationship name is wrong in 2nd query, while writing inner query for case it should be like from cases, it should not be from case

I tried as below and it did work for me

SELECT id, accountid, primary_contact__c, (select id from cases) FROM contact WHERE Phone = '+6491234567' order by primary_contact__c asc

1
  • A Single 'S' - The cause of my frustration was a single 's' - thank you for the quick response - the above worked perfectly. – TheDemonLord Apr 8 '19 at 22:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.