I have a lightning component that uses lightning file upload to tag a file at the ContentVersion level when it is uploaded. However, when bulk uploading files, only one of the documents gets tagged.
Any ideas on how I can force all to be tagged?
Component:
<aura:component controller="PODS_SuppDocContentVersion" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,force:lightningQuickAction" access="global" >
<aura:attribute name="options" type="List" default="[
{'label': 'Supporting Document', 'value': 'option1'},
]"/>
<aura:attribute name="value" type="List" default="option1"/>
<div class="slds-box slds-theme_default">
<div class="slds-media__body">
<h1 class="slds-card__header-title slds-truncate slds-align-middle--xx-small" title="Add Supporting Document"><b>Upload Supporting Document</b></h1>
<!-- Renders the File Upload and disabled checkbox -->
</div>
<lightning:fileUpload label=" " multiple="true" accept=".pdf, .docx, .doc" recordId="{!v.recordId}" onuploadfinished="{!c.handleUploadFinished}" />
<lightning:checkboxGroup name="Checkbox Group Disabled"
label=" "
options="{! v.options }"
value="{! v.value }"
disabled="true"/>
</div>
</aura:component>
Controller:
({
handleUploadFinished : function(component, event, helper) {
var action = component.get("c.updateContentVersion");
action.setParams({recId : component.get("v.recordId") });
$A.enqueueAction(action)
// Get the list of uploaded files
var uploadedFiles = event.getParam("files");
var toastEvent = $A.get("e.force:showToast");
toastEvent.setParams({
title : 'File Upload Complete',
message: "Your supporting document, "+uploadedFiles[0].name+", has been uploaded successfully.",
messageTemplate: 'Record {0} created! See it {1}!',
// duration:' 5000',
// key: 'info_alt',
type: 'success',
mode: 'sticky'
});
toastEvent.fire();
}
})
Apex:
public with sharing class PODS_SuppDocContentVersion{
@AuraEnabled
public static void updateContentVersion(String recId){
ContentVersion[] cvs = [SELECT ID, FirstPublishLocationId, Document_Type__c FROM ContentVersion WHERE FirstPublishLocationId = :recId ORDER BY CreatedDate DESC];
Cvs[0].Document_Type__c = 'Supporting Document';
update cvs[0];
}
}