You need to sign in to do that
Don't have an account?
IntroAmmy
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
Cmp.
<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%">
<center>
<lightning:fileUpload label="" multiple="{!v.multiple}"
accept="{!v.accept}" recordId="{!v.recordId}"
onuploadfinished="{!c.UploadFinished}" />
</center>
</div>
</div><br/>
<div class="slds-form--compound" style="position:relative">
<table class="slds-table slds-table--bordered">
<thead>
<tr>
<th></th>
<th>Title</th>
<th>FileType</th>
</tr>
</thead>
<tbody>
<aura:iteration items="{!v.files}" var="f">
<tr>
<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>
<td>{!f.FileType}</td>
</tr>
</aura:iteration>
</tbody>
</table>
<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>
</div>
</div>
</aura:if>
</div>
</div>
</div>
Js file.
({
doInit:function(component,event,helper){
helper.getuploadedFiles(component);
},
previewFile :function(component,event,helper){
var rec_id = event.currentTarget.id;
$A.get('e.lightning:openFiles').fire({
recordIds: [rec_id]
});
},
UploadFinished : function(component, event, helper) {
var uploadedFiles = event.getParam("files");
//var documentId = uploadedFiles[0].documentId;
//var fileName = uploadedFiles[0].name;
helper.getuploadedFiles(component);
component.find('notifLib').showNotice({
"variant": "info",
"header": "Success",
"message": "File Uploaded successfully!!",
closeCallback: function() {}
});
}
})
Apex class
@AuraEnabled
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){
documentIds.add(cdLink.ContentDocumentId);
}
cd = [SELECT Id,Title,FileType FROM ContentDocument WHERE id IN: documentIds];
return cd;
}
else
{
return cd;
}
}
Can someone plz help me on that
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
Cmp.
<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%">
<center>
<lightning:fileUpload label="" multiple="{!v.multiple}"
accept="{!v.accept}" recordId="{!v.recordId}"
onuploadfinished="{!c.UploadFinished}" />
</center>
</div>
</div><br/>
<div class="slds-form--compound" style="position:relative">
<table class="slds-table slds-table--bordered">
<thead>
<tr>
<th></th>
<th>Title</th>
<th>FileType</th>
</tr>
</thead>
<tbody>
<aura:iteration items="{!v.files}" var="f">
<tr>
<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>
<td>{!f.FileType}</td>
</tr>
</aura:iteration>
</tbody>
</table>
<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>
</div>
</div>
</aura:if>
</div>
</div>
</div>
Js file.
({
doInit:function(component,event,helper){
helper.getuploadedFiles(component);
},
previewFile :function(component,event,helper){
var rec_id = event.currentTarget.id;
$A.get('e.lightning:openFiles').fire({
recordIds: [rec_id]
});
},
UploadFinished : function(component, event, helper) {
var uploadedFiles = event.getParam("files");
//var documentId = uploadedFiles[0].documentId;
//var fileName = uploadedFiles[0].name;
helper.getuploadedFiles(component);
component.find('notifLib').showNotice({
"variant": "info",
"header": "Success",
"message": "File Uploaded successfully!!",
closeCallback: function() {}
});
}
})
Apex class
@AuraEnabled
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){
documentIds.add(cdLink.ContentDocumentId);
}
cd = [SELECT Id,Title,FileType FROM ContentDocument WHERE id IN: documentIds];
return cd;
}
else
{
return cd;
}
}
Can someone plz help me on that