I am looking for a way to retrieve all attachments from a particular object over a particular
Can I use Standard SFDC Email functionality to Email attachments retrieved from a SOQL?
I have the SOQL operating properly – I am basically wondering if I can use Apex to run the SOQL and attach the documents to an email.
Here is the SOQL…
SELECT Id FROM Attachment WHERE Parentid IN (Select Id from FF__Custom_Object__c WHERE recordtypeid = '0000000000000' AND Custom_Record_Age_Field_In_Days__c <= 31))
Below is some Apex that will hopefully get you started. I have tested this with a simpler SOQL query and it worked.
Depending on the number and size of the attachments you might run into issues here with the Heap size limits. In an email service context the heap size is 36 MB. Otherwise you will need to stay within 10MB, which isn't very large when dealing with multiple attachments.
It will probably be beneficial for the heap size to express the SOQL query directly in the for loop rather than first assigning it to a list and then looping over the list.
So rather than doing: