I have a LWC with a button to download a list of records in a CSV file. My code is:
const exportedFilename = 'issues.csv';
if(navigator.msSaveBlob){
navigator.msSaveBlob(blob, exportedFilename);
} else if (navigator.userAgent.match(/iPhone|iPad|iPod/i)){
const link = window.document.createElement('a')
link.href='data:text/csv;charset=utf-8,' + encodeURI(blob);
link.target="_blank"
link.download=exportedFilename
link.click()
} else {
const link = document.createElement("a")
if(link.download !== undefined){
const url = URL.createObjectURL(blob)
link.setAttribute("href", url)
link.setAttribute("download", exportedFilename)
link.style.visibility='hidden'
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
}
}
Where doc
is the variable where the data is formatted. It works fine in my scratch org, the problem is when I generate a managed package with this code and install it in another org. In that case, when you click the download button, the file downloaded is always empty and 0B and I have no idea why. Do you have any suggestion, please?