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
AJ MayerhoferAJ Mayerhofer 

How to handle files in Apex?

Hi all, I'm trying to create a button where the user can upload a pdf, and that pdf is then sent to the Docparser API.

What I currently have is the code from the Docparser API to send an Attachment object: https://github.com/Docparser/Docparser-Apex/blob/master/upload_document.apx

This would work, but I'm not sure how to get a pdf into an Attachment object, and I'm not sure if Attachment is even used in Apex anymore. There are "Salesforce Files" on Lightning which I have been able to manually upload pdfs to, but I'm not sure how to upload to/access them in code.

How do I get a pdf file into an Attachment or File (using an <apex:inputFile>)? What I need for sending information to Docparser is the name of the file and base64 encoded file data.

Thank you for any help.
Gaurav Sharma 472Gaurav Sharma 472
if you need to create an attcahment.
you need to create a new attachment reord.


if you want a file.
you need to create a new contentversion record