Hi #Ohana,
In this blog post, we will talk about how to develop a custom file Upload using Lightning Web Component.
We will create a Component that will upload the file under the file object instead of Attachment. The reason we are doing, Salesforce is deprecating the attachments.
We will use FileReader class of JavaScript to read the File and then send that to Salesforce.
We have designed the component which will sit inside the record page but if you want to use at different place then make the adjustment accordingly.
The main purpose of this component is to provide the ability to upload the Files even if you do not know the record Id and the record Id will be generated at run time.
Step 1 – Create the Apex Class
Step 2 – Create Lightning Web component
Get the code from the below file
Thanks for reading 🙂 #DeveloperGeeks #SalesforceDeveloper #SfdcPanther #AskPanther
Please do like share subscribe the SFDCPanther YouTube Channel.
This component would work for Guest user ?
Hi,
I have not tried this but you might need to make some tweaks to make it work for guest users.
Hi
can you please tell me how we change Upload files text to Attached file in lightning input type=’file’
thanks in adv.
That is something which is provided by Salesforce. If you wanted to change that you can try to do a hack using CSS. I have not tried this so I will not be able to provide you the code but you can try it.
Hello SFDC Panther. Amazing tutorial, it really helped me a lot!
However I have one question. My requirement was to create a possibility for a user to upload up to 9MB file size. I’ve googled it a bit and find out that I needed async call for it (I used @future) on appendToFile method.
However it doesn’t upload whole document. So if a document is 8.5 MB, it will once upload 7.5, and second time maybe 8.1 … you get the point. Do you know why this is happening and maybe you can give me some workaround on it?
Thanks in advance and keep up the good work 🙂
Hi Dame,
These are the Limitations of the JavaScript to upload the file which has Max Size Limit.
Hi SFDC Panther,
I have a query for file upload function. If we are using file upload in a form, File is going to get uploaded before the form gets saved. Suppose, if the user changes mind to not click on submit and clicks clear, is there any way we can delete the form ?
Any help will be much appreciated. Thanks in Advance
Are you able to elaborate more on your query, what you are trying to do?
Can I have this code on my email, I am in hurry and need to fix one functionality asap, Thanks in advance, One query I have a requirement to upload file upto 2GB which is saleaforce limit, will it be possible by this?
Hello,
Are you having any issues while using the code as the code is already there in the blog post?
And using this approach you can not upload more than 10MB file.
Hi Sir,
Its there in the Blog but I am not able to Copy it, also I need to upload the file upto 2GB(not 10 MB) and also I have to send it to apex(using chunking), Can you help me with any code snippet or blog.
Regards:
Arpit
The code is hosted in GitHub and to get the code you need to click on the View Raw button to see the code and use it. To upload the higher file of 2GB ( first thing if you will do your browser will be frozen after 30-40 MB size ). And if still want to upload then you have a Lighting-file upload standard lightning component which you can use.
Hi,
I have used this code for site user, earlier it worked. Now started giving no rows for assignment error .
message: “List has no rows for assignment to SObject”
stackTrace: “Class.FileUploadService.saveFiles: line 32, column 1\nClass.FileUploadService.saveTheChunkFile: line 8, column 1”
I debugged and checked that Content version id is created still query is returning null.
Regards,
Nitin
Please check your query and also the access level of the files that you are trying to access.
Is it possible to update the linked entity after save?
I have a checkbox I would like to update on the linked record?
I know this is probably a really simple thing to do but very new to Apex development.
K
Yes, you can update.As you already have the recordId for the Parent Record you can update it.
Great work, I have one concern though, if the file size crosses 6MB wouldn’t we run into heapsize limit? Instead we can have a VF page embedded within the component and update the versiondata using post
Yes. With a large file size, it will create a problem.You can give your version a try
Hello SFDC Panther,
I have created a LWC to upload file using Lightning file uploader, when we try to download or preview it, and downloaded file is not opening.
Could you please help me to figure out what might be wrong
It will be more helpful for me as I am new to salesforce.
if you I can provide you my code
Any help will be much appreciated
Thanks in advance
It’s not possible for me to review the code as I have other things to do. However if you have large size files then it will not be displayed in the previewed. When are you downloading the file make sure it is using right extension to save.
Hi Amit
Could you please give insights about the file size and chunk size. I’m unable to find salesforce document which can help to understand why chunksize is chosen as 750 kb.
The file chunk is not related to Salesforce it is related to JavaScript. We are uploading the file in chunks as uploading the file at once is not supported.
This was helpful thankyou very much!
Can you provide test class of this code
You have to develop the class
how to introduce accept format so that only pdf and doc can be uploaded
You need to add the validation in the JavaScript and check if the file name ends with .pdf or doc then only let them upload.