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
prasanth puvvada 4prasanth puvvada 4 

soql query error please help.


hi i written this query then showing error. please help.

this is working well. 
list<product2> pro=[select id,name,(select id from attachments) from product2   ];


But here i want to show only products which product records has attachments.  But getting error. 
list<product2> pro=[select id,name,(select id from attachments) from product2 where id in (SELECT ParentId FROM Attachment)  ];

 
Best Answer chosen by prasanth puvvada 4
RatanRatan
Looks like you can't do that.. Error Entity 'Attachment' is not supported for semi join inner selects

First store the ParentId then query based on paren Id
 
set<Id> setProduct2Ids = new set<Id>();
for(Attachment objAtt: [SELECT ParentId FROM Attachment]){
     setProduct2Ids .add(objAtt.ParentId);
}

list<product2> pro=[select id,name,(select id from attachments) from product2 where id in: setProduct2Ids  ];

 

All Answers

RatanRatan
Looks like you can't do that.. Error Entity 'Attachment' is not supported for semi join inner selects

First store the ParentId then query based on paren Id
 
set<Id> setProduct2Ids = new set<Id>();
for(Attachment objAtt: [SELECT ParentId FROM Attachment]){
     setProduct2Ids .add(objAtt.ParentId);
}

list<product2> pro=[select id,name,(select id from attachments) from product2 where id in: setProduct2Ids  ];

 
This was selected as the best answer
prasanth puvvada 4prasanth puvvada 4
love u ratan