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
Smita HodiggeriSmita Hodiggeri 

How to bulkify the following query to get all the notes and attachments in an org from any object (or obj is also fine)

I am looking to use the following query to bulk query all the notes and attachments in an org(or by object) so that I can do the migration of N&A's to Files (pre Spring '16 N&A's). Can someone give me a hand with this?
The results are way too many and I am hit with too many exceptions even for a month range. Can some one help get past that stupid error so that I can get a nice list of the notes & attchments created on accounts before 01012016?

I am looking to execute this in ANon window or just a simple SOQL query would be a dream!!
Your time and thoughts are much appreciated.
Thanks,

List<Account> accList = [SELECT Id,Name ,(SELECT RecordType FROM CombinedAttachments AS S WHERE (CreatedDate >= 2015-01-01T23:59:59Z AND CreatedDate < 2016-02-01T23:59:59Z)  AND (S.RecordType = 'Note' OR S.RecordType = 'Attachment'))  FROM Account];

Set<Id> accSetId = new Set<Id>(); 
for (Account acc :accList){
   if (acc.CombinedAttachments != null) {
      accSetId.add(acc.Id);
       system.debug('acc:'+acc);
   }
}
AnkaiahAnkaiah (Salesforce Developers) 
Hi Smita,

try with below code.  
List<Account> acclist = [select id from account];

List<Note> notes = [SELECT Id FROM Note WHERE ParentId = :acclist];
List<Attachment> attachments = [SELECT Id FROM Attachment WHERE ParentId = :acclist];

system.debug('attachments=='+attachments.size());
In the above i am quering Notes & attachemets related to the account object. Likewise you can do for other objects.

Refer the below link.
https://salesforce.stackexchange.com/questions/248812/what-is-the-right-way-to-query-all-notes-attachments

If this helps, Please mark it as best answer.

thanks!!