Activity Forums Salesforce® Discussions How to upload multiple attachments from Salesforce apex? please provide me some sample code

  • How to upload multiple attachments from Salesforce apex? please provide me some sample code

  • Tanu

    Member
    September 29, 2016 at 2:20 pm

    Hi All,

    I want to upload multiple attachments from apex? please provide me some sample code.

  • Gourav

    Member
    October 3, 2016 at 12:56 pm

    Hi Tanu,

    You can create an VF page to insert multiple attachments. Try this link to get more information according your requirement.

    http://forceguru.blogspot.in/2012/12/uploading-multiple-attachments-into.html

    Hope this will help you.

    Thanks.

  • Avnish Yadav

    Member
    September 29, 2018 at 8:28 pm

    Hello,
    ContentDocument object does not allow insert DML operation in Salesforce, so we can upload it through the ContentVersion object, without ContentDocumentId. After DML on ContentVersion a new version of ContentDocument will be created for us in salesforce.

    The easiest way to do this is using inputFile and assign it to ContentVersion instance. Like this:

    <apex:page controller="ContentController">
    <apex:form>
    <apex:inputfile value="{!file}"></apex:inputfile>
    <apex:commandbutton action="{!upload}" value="Upload"></apex:commandbutton>
    </apex:form>
    </apex:page>

    Class:
    public class ContentController {
    public blob file { get; set; }`

    public PageReference upload() {
    ContentVersion v = new ContentVersion();
    v.versionData = file;
    v.title = 'testing upload';
    v.pathOnClient ='/somepath.txt';
    insert v;
    return new PageReference('/' + v.id);
    }
    }

    If you want to share the ContentVersion file then after insert DML query the ContentDocumentId from inserted ContentVersion and use ContentDocumentLink to create association between Record and ContentVersion uploaded file.
    Thanks.

  • File Zipo

    Member
    December 29, 2021 at 8:35 am

    Hi,You can try File ZIPO, a native appexchange application that can help you to Add Multiple Salesforce files & attachments of any size or volume from External Cloud to Salesforce directly.
    For more info follow the given link - https://filezipo.io/add-files/

Viewing 1 - 4 of 4 posts

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos