You need to sign in to do that
Don't have an account?
Inserting a PDF in attachments object
What I wanted to do is I storing a PDF into attachments object through apex
Here is the apex code -
Now when I navigate to the object on which I have linked this attachment, click on the file it doesn't get loaded. Following error is displayed

There is something wrong while inserting the record.
Can somebody help me.
Note - I need pdf file to be attached to the object
Here is the apex code -
Blob body = Blob.valueOf('Some Text'); Attachment attach = new Attachment(); attach.Body = body; attach.Name = 'Sample.pdf'; attach.IsPrivate = false; attach.ParentId = '00641000004n7fEAAQ'; insert attach;
Now when I navigate to the object on which I have linked this attachment, click on the file it doesn't get loaded. Following error is displayed
There is something wrong while inserting the record.
Can somebody help me.
Note - I need pdf file to be attached to the object
Hello Mustafa,
You are trying to save this attachment in PDF format then you have to convert your string in blob.toPDF format.
Try this Code:
I hope this helps you. Mark this Answer as best Answer, if it helpful.
Thanks,
Yogesh Sharma