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
_LSDsl__LSDsl_ 

Semi-join problem (Cannot use a foreign key for outer field for semi join)

There is:

Object A , B, C.

 

B have lookup to A and C.

 

I need select all C that have relation with A .

 

Somethink like this:

 

C[] flAcs=[select ID from C where C.idB in (select ID from B where B.idA=:some_A_ID)];

 

but  on save I see error (Cannot use a foreign key for outer field for semi join) ((

 

SteveBowerSteveBower

Do you want:

 

select b.c_id from b where b.a_id = :some_a_id

 

i.e. the where B object is a joining object and has a lookup to A and a lookup to C

 

 

or, do you have A looking up to B, and C also looking up to B in which case do you want:

 

select c_id from c where c.b_id in (select a.b_id from a where a_id = :some_a_id))

 

In this case I think you're out of luck because of the foreign key restriction.  E.g. you can't do:

 

select Id from Opportunity where accountid in (select id from Account )

 

Of course if this is in Apex code, then you can break it into two queries with no problem.

 

Best, Steve.