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
VarunCVarunC 

I'm unable to fetch ALL my Attachment records via SOQL query

Every time I try to run this query i get only 2 results:

 

Attachments[] records = [Select Name, ParentId, OwnerId, Id, Body, ContentType, Description, IsPrivate From Attachment Where Parent.Type IN ('File__c') AND Owner.IsActive = true];

 

I know including "Body" field will limit number of records returned in Eclipse to only 1, BUT I'm using this query in APEX class and in Debug Log as well but I'm only able to read 2 record everytime, but the total count of Attachment record returned from this query Should be 4152 records which it is not giving.

 

Is it some Bug?

Best Answer chosen by Admin (Salesforce Developers) 
SuperfellSuperfell

You'll need to use the query loop syntax, 

 

for (Attachment [] atts : [select name, body from attachment]) {
// do something with atts
system.debug ( atts.size() );
}

All Answers

SuperfellSuperfell

You'll need to use the query loop syntax, 

 

for (Attachment [] atts : [select name, body from attachment]) {
// do something with atts
system.debug ( atts.size() );
}

This was selected as the best answer
VarunCVarunC

Thanks... That worked. 

 

But I actually even tried batching using StandardSetController for the query with pageSize of 1, 10 and 100 etc ... but using StandardSetController throwed "Internal Salesforce.com Error" ....

Fabian Manzano 6Fabian Manzano 6
Genious, thank you I was stuck for hours
batman jokerbatman joker
wow thanz this was great help! keep up the good work
Showbox (https://showbox.software/)| Kod (https://kodi.software/)i | Lucky Patcher (https://luckypatcher.pro/)|