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
ozhereozhere 

Cannot decode attachment body

Hi,

 

I am trying to decode attachment body with  this code:

 

             foreach($response->records as $attachment){         
                    $attachmentBody = $attachment->Body;
                    echo base64_decode($attachmentBody);                   
                }

But the result is null. 'Echo $attachmentBody' prints some unreadable text. What is the right way to decode attachment body?

 

Thank you,

-O

Best Answer chosen by Admin (Salesforce Developers) 
GLacordelleGLacordelle
Could you please give us more details about your problem?
What result is null?
Which is the Content-Type of the attachment body?

All Answers

GLacordelleGLacordelle
Could you please give us more details about your problem?
What result is null?
Which is the Content-Type of the attachment body?
This was selected as the best answer
ozhereozhere

Hi Murray,

 

Thank you for your reply. I got the problem solved, and the reason was not decoding code.

The problem was if only one attachment is returned and (is_object($attachments->records), the records should be retrieved differently from (is_array($attachments->records)).

 

Thanks,

-O