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
Westec Intelligent Surv.Westec Intelligent Surv. 

Need an API query matching the Notes And Attachments section of an Account

I tried this in the Apex Coding board, the solution was invalid. Basically, I need a single query, executable using the API, that will return all NoteAndAttachment items that would normally show in the Notes And Attachments section of an Account page in the Web UI. This includes not only N&A that are attached to the parent, but also those that are attached to any Case, Opportunity, or Contact that is related to the account. Salesforce itself seems to have no problem getting that information, but between SOQL limitations and restrictions on the data model, I have yet to find a satisfactory solution.

 

Here's what I have so far:

 

 

SELECT Id,
(select Id, Title, IsNote from NotesAndAttachments),
(select Id, Title, IsNote from Contacts.NotesAndAttachments),
(select Id, Title, IsNote from Cases.NotesAndAttachments),
(select Id, Title, IsNote from Opportunities.NotesAndAttachments)
FROM Account a WHERE Id = '{0}'

 

 

The {0} is for use with a .NET String.Format; it'll be the account ID I'm pulling records for. This particular query fails with the following exception:

 

 

System.Web.Services.Protocols.SoapException : INVALID_FIELD: 
(select Id, Title, IsNote from Contacts.NotesAndAttachments),
                               ^
ERROR at Row:3:Column:48
Didn't understand relationship 'Contacts' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.

 

These are all basic, system-defined relationships, and it didn't recognize the singular "Contact" either, so I'm at a loss.

 

 

Other solutions have involved semi-join sub-selects (there's a limit of two and you can't combine them with OR so no dice), nested subqueries (can't subquery more than one level deep from the root), etc. I'm really at my wits end with this query language's limitations; no UNION, limited subqueries, limited subquery depth, and the NoteAndAttachment entity cannot be queried directly. There simply has to be a way to get these records the same way they're shown in the website, but I'm being frustrated at every turn..

 

mohimohi

NotesandAttachment is child relationship with contact,Contacts.NotesandAttachment is not acceptable,and if u make here parent to child query for contact,query statement more than 1 level is not accepted.you have to make different workaround