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
SeAlVaSeAlVa 

Attachment body mismatch

Hi everybody, 

 

lets see if I'm missing anything or something because I think this might be a salesforce bug.

 

I am developing a REST webservice, see the following code snippet.

 

...
        returned.signatures = new List<Map<String,String>>();
        for(Attachment att : [
            SELECT
                Body,
                ParentID
            FROM
                Attachment
            WHERE 
                ParentID IN :new Map<ID,Order__c>(returned.orders).keyset() AND
                Name like 'Signature%']){
                

                System.debug(att.id);
                System.debug(att.parentID);
                system.debug(EncodingUtil.base64Encode(att.body));

                returned.signatures.add(new Map<String,String>{'Id'=>String.valueOf(att.parentID),'signatureBody'=>EncodingUtil.base64Encode(att.body)});        
        }
...

 

 

The thing is that if I go to the debug logs, 

I see the attachment ID and the parentID properly, but the att.body is from another file :S (if I navigate to the AttachmentID and click on View, I see the good one)

 

Is there anything that I am doing wrong?

Gunners_23Gunners_23

I would rather try to keep my SOQL simple by fetching the Object's records and related attachments. Something like

 

List<Account> accList = new List<Account>();
accList = [SELECT Id,Name,(SELECT Id FROM ATTACHMENTS) From Account];