0

I have a requirement where i need to upload files into an object related list(notes & attachments section),i just written a code in component and controller, but it does'nt seems to be worked,please help me with the solution

here is the code :

component

    <aura:attribute name="filetype" type="List" default="['.png', '.jpg', '.jpeg']" />
         <aura:attribute name="multiple" type="Boolean" default="true" />
          <aura:attribute name="recordId" type="String" /> <lightning:recordeditform>      <fieldset class="slds-form--compound">
                    <legend class="slds-form-element__label">Attachments</legend>   
                    <div class="form-element__group">
                            <lightning:fileUpload label="upload file" name="fileuploader" multiple="{!v.multiple}" accept="{!v.filetype}" recordId="{!v.recordId}" onuploadfinished="{!c.uploadfinished}"/>
                             </div>
                            </fieldset> </lightning:recordeditform>

controller

     uploadfinished : function(cmp , event , helper){
            var uploadedfiles = event.getParam("files");
            var docid= uploadedfiles[0].docid;
            var fileName= uploadedfiles[0].name;
            var toastevent = $A.get("e.force:showToast");
            toastEvent.setParams({
                "title" : "success!",
                "message" :"File "+fileName+" Uploaded Successfully."
            });
            toastEvent.fire();
            $A.get('e.lightning:openFiles').fire({
                recordIds : [docid]
            });
            
        }

please help me with complete code if u have code

2
  • I strongly suggest instead of using SF Attachments you use SF Files. SF has made it clear that gradually they will move from attachments to files. – Boris Gichev Jan 19 at 12:14
  • If you can go with files, here you can see detail about the file data model structure.developer.salesforce.com/docs/atlas.en-us.api.meta/api/… If you can go with files I can give you more extensive example, but I have not done this with attachments. – Boris Gichev Jan 19 at 12:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.