Currently I am letting user to upload multiple PDF Files. Now I have created a service outside of salesforce that will merge multiple PDF into one. I need to convert those PDF Files into base64 in order to send them into the service files. can I convert the pdf files into base54 without inserting them into Document Object?

public void save()
        List<Attachment> toInsert=new List<Attachment>();
        for (Attachment newAtt : newAttachments)
            if (newAtt.Body!=null)
                newAtt.OwnerId = UserInfo.getUserId();
        insert toInsert;
        newAttachments.add(new Attachment());



<apex:component controller="MultiAttachmentController" allowDML="true">
    <apex:attribute name="objId" type="String" description="The id of the object to manage attachments for" required="true" assignTo="{!sobjId}"/>
    <apex:form id="attForm">
        <apex:pageBlock title="Upload Attachments">
            <apex:repeat value="{!newAttachments}" var="newAtt">
                <apex:pageBlockSection columns="3">
                   <apex:pageBlockSectionItem >
                        <apex:outputLabel value="File"/>                         
                        <apex:inputFile value="{!newAtt.body}" filename="{!newAtt.name}"/>
                    <apex:pageBlockSectionItem >
                        <apex:outputLabel value="Description"/>                      
                        <apex:inputText value="{!newAtt.Description}"/>
            <apex:commandButton value="Add More" action="{!addMore}"/>
            <apex:commandButton value="Save" action="{!save}"/>
            <apex:commandButton value="Done" action="{!done}"/>
    <apex:pageBlock title="Existing Attachments">
        <apex:pageBlockTable value="{!attachments}" var="attachment">
            <apex:column headerValue="Action">
               <apex:outputLink value="{!URLFOR($Action.Attachment.Download, attachment.Id)}" target="_blank">View</apex:outputLink>
            <apex:column value="{!attachment.Name}"/>
            <apex:column value="{!attachment.Description}"/>
        <apex:pageBlockTable value="{!documents}" var="document">
            <apex:column >
                <apex:outputLink value="/{!document.Id}">{!document.Name}</apex:outputLink>

1 Answer 1


document object's body field type is base64.

You dont have to convert

If you have string with base64 data.

then use encodingutil.base64decode for convertion


  • Converts a Base64-encoded String to a Blob representing its normal form.


  • Converts a Blob to an unencoded String representing its normal form.

Encodingutil class https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_restful_encodingUtil.htm

  • but on the save action should I insert the pdfs into Document object before using encodingutil.base64decode. I just added a code I have in my question
    – Metawaa
    Dec 17, 2015 at 16:54
  • Yes if you are using newAtt.Body in <apex:inputfile >
    – Ratan Paul
    Dec 17, 2015 at 16:57
  • Is there something else I can do besides doing newAtt?
    – Metawaa
    Dec 17, 2015 at 16:59
  • no you don't have to do anything. Can you pls add your VF page code? what you are trying to achieve ?
    – Ratan Paul
    Dec 17, 2015 at 17:01
  • I just did, Sorry I may be little bet behind in coding . I am taking baby steps
    – Metawaa
    Dec 17, 2015 at 17:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .