当前位置:网站首页>Salesforce file (II) custom development fileUpload

Salesforce file (II) custom development fileUpload

2022-06-23 02:12:00 repick

Use 【lightning-file-upload】 Custom development of tags .

fileUploadLWC.html

<template>
  <lightning-card title="LWC File Upload Example" icon-name="custom:custom19">
      <lightning-file-upload
          label="Attach receipt"
          name="fileUploader"
          accept={acceptedFormats}
          record-id={recordId}
          onuploadfinished={handleUploadFinished}
          multiple>
  </lightning-file-upload>
  </lightning-card>
</template>

fileUploadLWC.js

import { LightningElement, api } from 'lwc';
import {ShowToastEvent} from 'lightning/platformShowToastEvent';
export default class FileUploadLWC extends LightningElement {
    @api recordId;
    get acceptedFormats() {
        return ['.pdf', '.png','.jpg','.jpeg'];
    }
    handleUploadFinished(event) {
        // Get the list of uploaded files
        const uploadedFiles = event.detail.files;
        let uploadedFileNames = '';
        for(let i = 0; i < uploadedFiles.length; i++) {
            uploadedFileNames += uploadedFiles[i].name + ', ';
        }
        this.dispatchEvent(
            new ShowToastEvent({
                title: 'Success',
                message: uploadedFiles.length + ' Files uploaded Successfully: ' + uploadedFileNames,
                variant: 'success',
            }),
        );
    }
}

fileUploadLWC.js-meta.xml

<?xml version="1.0" encoding="UTF-8"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
    <apiVersion>52.0</apiVersion>
    <isExposed>true</isExposed>
    <targets>
        <target>lightning__AppPage</target>
        <target>lightning__RecordPage</target>
        <target>lightning__HomePage</target>
    </targets>
</LightningComponentBundle>

1. hold Lwc Configuration to Account detailed page On .

2. Effect display

3. Next, let's see where the uploaded files are saved , Follow current Account The relationship between .

i. Start with the current AccountId On condition that , Yes 【ContentDocumentLink】 Perform the following search .

SELECT Id, LinkedEntityId, ContentDocumentId,
IsDeleted, SystemModstamp, ShareType, Visibility
FROM ContentDocumentLink
where LinkedEntityId = '0016g000005bsfJAAQ'
ContentDocumentId:
0696g00000G0xO1AAJ,0696g00000I0rkiAAB,0696g00000I2Fa0AAF

ii. Then the search result of the above side is a conditional pair Object【ContentDocument】 Search

SELECT Id, CreatedById, ArchivedDate,
IsDeleted, OwnerId, SystemModstamp, Title,
PublishStatus, LatestPublishedVersionId,
ParentId, LastViewedDate, LastReferencedDate,
Description, ContentSize, FileType
FROM ContentDocument
where Id in ('0696g00000G0xO1AAJ','0696g00000I0rkiAAB','0696g00000I2Fa0AAF')

iii. Then the search result of the above side is a conditional pair Object【ContentVersion】 Search

SELECT Id, ContentDocumentId, IsLatest, ContentUrl,
ContentBodyId, VersionNumber, Title
FROM ContentVersion
where ContentDocumentId in ('0696g00000G0xO1AAJ','0696g00000I0rkiAAB','0696g00000I2Fa0AAF')

summary , Through the above query , We found that the uploaded files were finally stored in 【ContentDocumentLink】【ContentDocument】【ContentVersion】 In the table .

原网站

版权声明
本文为[repick]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202091754070484.html