0

I use the following query to get the data, but i also want to receive more fields from the "soco__Volunteer_Assignment__c" object.

SELECT+FIELDS(ALL),Account.Name,Account.Id+FROM+Contact+WHERE+Id+IN+(SELECT+soco__Contact__c+FROM+soco__Volunteer_Assignment__c+WHERE+soco__Status__c='Active'+LIMIT+2+OFFSET+0

How do I receive more fields from this object?

SELECT+FIELDS(ALL),Account.Name,Account.Id+FROM+Contact+WHERE+Id+IN+(SELECT+soco__Contact__c,soco__End_Date__c+FROM+soco__Volunteer_Assignment__c+WHERE+soco__Status__c='Active'+LIMIT+2+OFFSET+0

placing the fieldname "soco__End_Date__c" in the second select query will receive the folowing error message:

[
    {
        "message": "\nWHERE Id IN (SELECT soco__Contact__c,soco__End_Date__c FROM soco__Volunteer_Assignment__c\n                                   ^\nERROR at Row:1:Column:321\nunexpected token: ,",
        "errorCode": "MALFORMED_QUERY"
    }
]
2
  • The error message says the field Id only receives the ID values, not an object soco__Volunteer_Assignment__c.
    – Raj
    Commented Jan 4, 2022 at 16:09
  • 1
    Please only ever add the [community] badge if you are asking a question related to the Salesforce Community Cloud feature (also called Experience Cloud).
    – Adrian Larson
    Commented Jan 4, 2022 at 16:43

1 Answer 1

1

It's a different type of join to retrieve child objects than it is to filter on them. There used to be really good documentation on join syntax, but it seems to have disappeared.

I believe what you already have is a Left Inner Join, and what you need to add is a Left Outer Join. In this terminology, Left indicates a child table, and Right indicates a parent table. Further, Inner indicates joining via WHERE filtering, whereas Outer indicates pulling in records/fields via SELECT clause.

Anyway, what you need should look like:

SELECT FIELDS(ALL), Parent.Field, (SELECT Field__c FROM Children__r)
FROM Contact WHERE Id IN (SELECT Contact_Lookup__c FROM Child__c)

Note the names in the FROM clause are different in the two joins. When pulling child records into your SELECT clause, you need to use the Child Relationship Name, whereas you use the Qualified API Name when joining via your WHERE clause.

3
  • Thanks, by using this method I receive the following message SELECT+FIELDS(ALL),Account.Name,(SELECT+soco__End_Date__c+FROM+soco__Volunteer_Assignment__r)+FROM+Contact+WHERE+Id+IN+(SELECT+soco__Contact__c+FROM+soco__Volunteer_Assignment__c)
    – Johan
    Commented Jan 4, 2022 at 16:29
  • ``` [ { "message": "\n(SELECT soco__End_Date__c FROM soco__Volunteer_Assignment__r) FROM\n ^\nERROR at Row:1:Column:64\nDidn't understand relationship 'soco__Volunteer_Assignment__r' in FROM part of query call. 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.", "errorCode": "INVALID_TYPE" } ] ```
    – Johan
    Commented Jan 4, 2022 at 16:31
  • 1
    How do I find the child relationship name?
    – Adrian Larson
    Commented Jan 4, 2022 at 16:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .