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

  • 1
  • Question
  • Updated 2 years ago
  • Answered
  • (Edited)
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,
Photo of Rajendra Rathore

Rajendra Rathore

  • 1,480 Points 1k badge 2x thumb

Posted 4 years ago

  • 1
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
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. 
Photo of Rajendra Rathore

Rajendra Rathore

  • 1,480 Points 1k badge 2x thumb
Thanks Rob

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

Thanks you So much :)
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
Glad to hear! 
Photo of Rebecca Vanderslice

Rebecca Vanderslice

  • 376 Points 250 badge 2x thumb
i love this solution!  adding this to my page now.
Photo of Ryan Faust

Ryan Faust

  • 884 Points 500 badge 2x thumb
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!!