Show Notes related to a Account as well as Notes related to That Account.Contacts

Hi,

On Account detail page i want to show all “Notes” that are related to Current account as well as notes that are releated Account—>Contacts.

So Baically is used Join with Sub query to add filter on ParentId in Account.Contact Id OR ParentId =Account.id

But when i’m running that page then getting following error:

An error occurred while attempting to perform the following SOQL query: SELECT Body,Title,ParentId,Parent.Name,Id FROM Note WHERE ((ParentId in (SELECT Id FROM Contact WHERE (((AccountId = ‘001d000001ar9NEAAY’)))))OR(ParentId = ‘001d000001ar9NEAAY’)) ORDER BY LastModifiedDate DESC LIMIT 101 Error: Semi join sub-selects are not allowed with the ‘OR’ operator

Can one one please let me know how i use OR Condition with Sub Query.

Thanks,

Yes,  Salesforce is going to yell at you when you try to use Or statements in subqueries.   But never fear - there is another way. 

1. I assume you already have other models that give you Account ID’s and Contact ID’s that are relevant for this page. 
2. Create 2 conditions in your Notes model that retrieve notes where the parent ID’s are IN the list of ID’s from the Account model   – OR – are IN the list of ID’s from the contacts model.   Here is where the model chaining availalble in “field from another model” conditions is really powerful. 

Thanks Rob

I used  “IN” Condition on contact model and now its working fine.

Thanks you So much :slight_smile:

Glad to hear! 

i love this solution!  adding this to my page now.

Rob - just wanted to let you know, 2 years later and this tip is still being used! I’ve been working an hour wondering why my logic wasn’t working, finally searched and found the IN condition tip as opposed to the = condition. Awesome!!