I want to retrieve Notes And Attachments that are attached with the record of a custom object in a single query .How can i do this?

SELECT Id,Name,(SELECT Id,Title FROM Notes),
               (SELECT Id,Name FROM Attachments) 
  FROM My_Custom_Object__c WHERE id='01a4s7dfsaawZAE'

i have tried to solve it using the above query but through this i am not able to acces notes and attachments in apex.if i run this query in developer console it is showing me the notes and attachments of that record.How can i access same in apex.

  • when i am running query SELECT Id,Title FROM Note WHERE ParentID ='a06J0000004SKaa' in developer console it is returning 1 row correctly.but the same query when i am running in apex it is giving null.what's the issue?
    – Pankaj
    Mar 25, 2013 at 8:03

1 Answer 1


You might have applied with sharing in class declaration and that particular record would not be accessible to respective user. that is why you can see records in developerr console but getting null in apex code. with sharing enforce the sharing rules that apply to the current user.

To know more about with sharing Click Here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .