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

I Need to upload file via community user at the time of lead creation

I need to add functionality to upload file while i am creating Lead record form Community.
when I create lead from community that file(pdf,jpg, etc) need to be uploaded and associated with same Lead record 

I have tried for existing lead record. it worked , but i have few lead field on my page when i fill the details and upload file the lead shoul be created and file shoud be attached with lead record


<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>  
    <aura:attribute name="files" type="ContentDocument[]"/>  
    <aura:attribute name="recordId" type="string" default="00Q6C00000Pt5kv"/>  
    <aura:attribute name="accept" type="List" default="['.jpg', '.jpeg','.pdf','.csv','.xlsx']"/>  

    <aura:attribute name="multiple" type="Boolean" default="true"/>     
    <aura:attribute name="Spinner" type="boolean" default="false"/>

<div class="slds">  
        <lightning:notificationsLibrary aura:id="notifLib"/>
        <div class="contentbox">  
            <div class="slds-page-header header">Files</div>  
            <div class="slds-grid">  
                <div style="width:100%">  
                        <lightning:fileUpload label="" multiple="{!v.multiple}"   
                                              accept="{!v.accept}" recordId="{!v.recordId}"   
                                              onuploadfinished="{!c.UploadFinished}" />  
            <div class="slds-form--compound" style="position:relative">
                <table class="slds-table slds-table--bordered">  
                        <aura:iteration items="{!v.files}" var="f">  
                                <td><a href="javascript:void(0)" id="{!f.Id}" onclick="{!c.delFiles}">Delete</a></td>
                                <td><a href="" id="{!f.Id}" onclick="{!c.previewFile}">{!f.Title}</a></td>  
                <aura:if isTrue="{!v.Spinner}">
                    <div class="slds-spinner_container">
                        <div class="slds-spinner slds-spinner--medium" aria-hidden="false" role="alert">
                            <div class="slds-spinner__dot-a"></div>
                            <div class="slds-spinner__dot-b"></div>

Js file.

    previewFile :function(component,event,helper){  
        var rec_id =;  
            recordIds: [rec_id]
        UploadFinished : function(component, event, helper) {  
        var uploadedFiles = event.getParam("files");  
        //var documentId = uploadedFiles[0].documentId;  
        //var fileName = uploadedFiles[0].name; 
            "variant": "info",
            "header": "Success",
            "message": "File Uploaded successfully!!",
            closeCallback: function() {}

Apex class

    public static List<ContentDocument> getFiles(string recordId){ 
        // TO avoid following exception 
        // System.QueryException: Implementation restriction: ContentDocumentLink requires
        // a filter by a single Id on ContentDocumentId or LinkedEntityId using the equals operator or 
        // multiple Id's using the IN operator.
        // We have to add sigle record id into set or list to make SOQL query call
        Set<Id> recordIds=new Set<Id>{recordId};
        Set<Id> documentIds = new Set<Id>(); 
        List<ContentDocumentLink> cdl = new List<ContentDocumentLink>();
        List<ContentDocument> cd = new List<ContentDocument>();
        cdl= [SELECT id,LinkedEntityId,ContentDocumentId FROM ContentDocumentLink WHERE LinkedEntityId = '0051I000006c7f7QAA'];
        if (!cdl.isEmpty()){
           for(ContentDocumentLink cdLink:cdl){  
        cd = [SELECT Id,Title,FileType FROM ContentDocument WHERE id IN: documentIds];  
            return cd;
           return cd;


Can someone plz help me on that