Make a Lightning Button Download a .html Report
The Attachment object is for saving data to the database. It has a number of fields, which is why you're seeing [object Object]
. Instead, you should be able to do so with code like this:
@AuraEnabled public static String getFile() {
String htmlText = '<html>...</html>';
return EncodingUtil.base64Encode(Blob.valueOf(htmlText));
}
action.setCallback(this, function(response) {
let state = response.getState();
if (state === "SUCCESS") {
let downloadLink = document.createElement("a");
downloadLink.href = "data:text/html;base64,"+response.getReturnValue();
downloadLink.download = "filename.html";
downloadLink.click();
} ...