You need to sign in to do that
Don't have an account?
Wolf Duttlinger 6
Find parents without children for self referencing objects
Hi all,
we are using cases in various recordtypes (A, B). Every A should normally have a B as a child. I'm trying to find those that haven't one.
select case.id, case.CaseNumber from case where case.id not in (select case.parentid from case) and case.recordtype.name = 'A'
--> The inner and outer selects should not be on the same object type
select case.id, case.CaseNumber from case where case.recordtype.name = 'Service Case' and (select count() from case.cases) = 0
--> Unknown error parsing query
select id, CaseNumber from case a where not exists (select id from case b where b.parentid = b.id ) and a.recordtype.name = 'A'
--> Unknown error parsing query
Any suggestions????
Thanks
Wolf
we are using cases in various recordtypes (A, B). Every A should normally have a B as a child. I'm trying to find those that haven't one.
select case.id, case.CaseNumber from case where case.id not in (select case.parentid from case) and case.recordtype.name = 'A'
--> The inner and outer selects should not be on the same object type
select case.id, case.CaseNumber from case where case.recordtype.name = 'Service Case' and (select count() from case.cases) = 0
--> Unknown error parsing query
select id, CaseNumber from case a where not exists (select id from case b where b.parentid = b.id ) and a.recordtype.name = 'A'
--> Unknown error parsing query
Any suggestions????
Thanks
Wolf
Let me know if this solves your issue.
Maybe I don't see it - but this doesn't solve the problem. Your example would require 'B' to exist - which should not be the case.
I have
I need the result to be "3"
Regards
Wolf
Let me know if this helps.
yes - coding it in APEX solves the problem. I just did hope a single SOQL would do the trick..... SQL would do it....
Wolf
Perhaps I did not understand completly your data structure but you may try below
select case.id, case.CaseNumber from case where case.recordtype.name = 'A' and parent.id=null