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
Monishan MMonishan M 

How to query only the parent records which has child records and eliminate the parent records which doesnt have child

Hi,

I have below query built. But this query fetches even the suggestion_vod__c records which doesnt have suggestion_tags_vod__c records.

I need to fetch only the suggestion_vod__c records which have suggestion_tags_vod__c records. I need to eliminate the suggestions which doesnt have suggestion tags.

Could you please help me in the query

For(Suggestion_vod__c S :[Select  id,account_vod__c,Expiration_Date_vod__c ,OwnerId,Created_Based_on_CVMD_Respi_AZ_JP__c,
 Marked_As_Complete_vod__c,Patients_ID_AZ_JP__c,Dismissed_vod__c,Created_Based_on_Cycle_Plan_Rule_AZ_JP__c,
 (Select id,Product_vod__c,Suggestion_vod__c from Suggestion_Tags_vod__r) 
 from suggestion_vod__c 
  where Expiration_Date_vod__c >= Today 
   AND Marked_As_Complete_vod__c = Null 
   AND Dismissed_vod__c = Null

Suggestion_tag_vod__c object has a master detail relationship with Suggestion_vod__c object.
David Zhu 🔥David Zhu 🔥
You may try the following soql:

Select  Suggestion_vod__r.id,Suggestion_vod__r.account_vod__c,Suggestion_vod__r.Expiration_Date_vod__c ,Suggestion_vod__r.OwnerId,Suggestion_vod__r.Created_Based_on_CVMD_Respi_AZ_JP__c,Suggestion_vod__r.Marked_As_Complete_vod__c,Suggestion_vod__r.Patients_ID_AZ_JP__c,Suggestion_vod__r.Dismissed_vod__c,Suggestion_vod__r.Created_Based_on_Cycle_Plan_Rule_AZ_JP__c,id,Product_vod__c from Suggestion_Tags_vod__c where Suggestion_vod__r.Expiration_Date_vod__c >= Today AND Suggestion_vod__r.Marked_As_Complete_vod__c = Null AND Suggestion_vod__r.Dismissed_vod__c = Null