0

I am trying to create a SOQL statement like this:

SELECT Lookup__c
FROM Reference__c
WHERE Type__c = 'Country - Country Code'
      AND Return__c IN
          (SELECT Linked_Address__CountryCode__s
           FROM Timeline__c
           WHERE Client__c = ':Id'
                 AND ELS__c = TRUE
                 AND Status__c != 'Closed')

When I run it in the developer console (with a hardcoded Id of course) I get an UNKNOWN_EXCEPTION error. I have tried running both parts of the query separately and that works (the nested query returns 'GB', and when I hard code that into the outer query it returns 'United Kingdom' as expected), but when I combine them it doesn't. Can anyone tell me what I am doing wrong here?

3
  • In the developer console, go to Help -> Preferences and check the box to Enable Query Plan. It changes between True/False and a checkbox when you try to change it. Click Save. The Query Editor tab will then show you the Query Plan button, which will give you more information about what is wrong with the query.
    – Derek F
    Commented Nov 8 at 15:13
  • 4
    Best guess right now is that the Client__c = ':Id' part is wrong (we can't do any variable binding in the dev console's query editor), or that your semi-join isn't working on relationship fields (semi-joins only work for relationship fields) or that the semi-join is returning an Id for an SObject other than the one that Return__c is for.
    – Derek F
    Commented Nov 8 at 15:18
  • 1
    The syntax when you do have bindings is Client__c = :bindingname - no quotes around the binding reference. What did you actually change the syntax to when using the dev console?
    – Phil W
    Commented Nov 8 at 16:31

1 Answer 1

0

I don't seem to be able to mark a comment as the correct answer, however Derek F wrote: "semi-joins only work for relationship fields". That is exactly my problem, there is no defined relationship between Timeline and Reference. So I will somehow have to do this in two separate queries.

Thank you Derek F.

You must log in to answer this question.

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