Play Games

Search This Blog

Wednesday, September 9, 2020

How to upload files from aura component salesforce Lightning - Salesforce Globe For You

 How to upload files from aura component salesforce Lightning  - Salesforce Globe For You 

Solution:Use <lightning:fileUpload> component in aura component to upload files.

To associate the uploaded file to salesforce record,assign the recordId of that record to the 'recordId' attribute of <lightning:fileUpload> component.

Example:

fileUpload.cmp

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,

forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global"><aura:attribute name="recordId" type="String" />

 <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>

<div class="slds-page-header">

 <div class="slds-align_absolute-center slds-text-title_bold" style="height:5rem">File Upload</div>

 <lightning:fileUpload label="Attach File" name="fileUploader" multiple="true"  recordId="{!v.recordId}" onuploadfinished="{!c.handleUploadFinished}" />

 </div>

</aura:component>

fileUploadController.js

({

doInit : function(component, event, helper) {

 },

handleUploadFinished : function(component, event, helper) {

var recordId = component.get('v.recordId');

var str = "Files uploaded to Notes and Attachment under this record"+recordId;

alert(str);

 }

})

You can drag and drop this component to any record detail page to test.

In this example I dragged this component to Lead record page and uploaded the file.

Output:





No comments:

Post a Comment