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

Child relationship queries help?

Hi i have a custom object called sales order now i want to find out all the sales orders that have a note or attachment

i done this but i am not sure how to define to only show if there is an attachment or note

Select s.Id, (Select Id, ParentId From Notes), (Select Id, ParentId From Attachments) From SCRB_SalesOrder__c s


this doesn't work?

Select s.Id, (Select Id, ParentId From Notes Where Id != null),
(Select Id, ParentId From Attachments Where Id != null) From SCRB_SalesOrder__c s

You can't run a query using that notation-- it simply won't work (outer joins do not exist that way yet).

Instead, run a query on the notes and attachments:

select id, parentid from attachment where parent.type = 'SCRB_SalesOrder__c'
select id, parentid from note where parent.type = 'SCRB_SalesOrder__c'