You need to sign in to do that
Don't have an account?
Dbjensen
SQOL: Only return results if there is a child record
Hello - How can I prevent this query from returning results if there is no child lead? In other words, I just want the qurey to return the contact if it has a child lead record.
for(Contact contactQueryList : [SELECT ID, (SELECT Id FROM Leads__r) FROM Contact WHERE ID IN :contactsIds]){ contactQueryList.Contact_Sync_to_Marketing_Cloud__c = true; System.debug('contact found '+contactQueryList); updateContactList.add(contactQueryList); }Thanks for any help you can provide.
Try any one of the below ways:
1. use the if condition to check the child size:
2. Use the child soql query in parent where condition. I have considered your parent lookup field as contact__c from so use the correct api name from lead object. https://salesforce.stackexchange.com/questions/152519/soql-to-determine-if-parent-has-child-records
Thanks,
Maharajan.C
All Answers
Try any one of the below ways:
1. use the if condition to check the child size:
2. Use the child soql query in parent where condition. I have considered your parent lookup field as contact__c from so use the correct api name from lead object. https://salesforce.stackexchange.com/questions/152519/soql-to-determine-if-parent-has-child-records
Thanks,
Maharajan.C
You can take reference from this below code. In case you find any other issue please mention.
If you find your Solution then mark this as the best answer.