You need to sign in to do that
Don't have an account?
Joseph Murawski
recordId not being refreshed in Lightning component helper method
I have a custom lightning component that uses:
<input type="file" class="slds-file-selector__input slds-assistive-text"
onchange="{!c.saveFile}" aura:id="file"
accept="image/png;image/jpg;image/gif" id="file-upload-input-01"
aria-labelledby="file-selector-primary-label file-selector-secondary-label" />
to upload a file (Attaching code for saveFile function).
My problem is that when I use the component on account record and then switch to another record, when I process the upload on the other record it still uses the account record ID in the save routine. I have checked to make sure the component recordId from the hasRecordId is loading correctly.
<input type="file" class="slds-file-selector__input slds-assistive-text"
onchange="{!c.saveFile}" aura:id="file"
accept="image/png;image/jpg;image/gif" id="file-upload-input-01"
aria-labelledby="file-selector-primary-label file-selector-secondary-label" />
to upload a file (Attaching code for saveFile function).
My problem is that when I use the component on account record and then switch to another record, when I process the upload on the other record it still uses the account record ID in the save routine. I have checked to make sure the component recordId from the hasRecordId is loading correctly.
ComponentController: saveFile: function(component,event,helper) { helper.showSpinner(component,"spinner"); helper.uploadMe(component,event,helper); }, Helper: upload: function(component, file, base64Data, helper,event) { var action = component.get("c.saveAttachment"); action.setParams({ parentId: component.get("v.recordId"), fileName: file.name, base64Data: base64Data, contentType: file.type }); console.log("c.saveAttachment time start: " + Date.now()) action.setCallback(this, function(a) { console.log("c.saveAttachment time callback returned: " + Date.now()) var state = a.getState(); if (state === "SUCCESS") { console.log("c.saveAttachment time callback success: " + Date.now()) helper.hideSpinner(component,"spinner"); component.set("v.message", ""); component.set('v.deleteIconClass', 'slds-float--right slds-p-right_small'); helper.ToastMe(component, event, helper, "success", "Image uploaded"); $A.get('e.force:refreshView').fire(); } else { component.set("v.message", ""); helper.ToastMe(component, event, helper, "error", "Image Upload Failed"); } }); console.log("c.saveAttachment time callback queued: " + Date.now()) $A.enqueueAction(action); }, uploadMe: function(component,event,helper) { var fileInput = component.find("file").getElement(); var file = fileInput.files[0]; var fSize = 0; if (!file) return; if (!file.type.match(/(image.*)/)) { helper.ToastMe(component, event, helper, "error", "Image file not supported"); return; } if (file.size > this.MAX_FILE_SIZE_SM) { fSize = 1; helper.ToastMe(component, event, helper, "error", "File needs to be less than 1024 KB. Current size: " + file.size); return; } var self = this; var fr = new FileReader(); fr.onloadend = function() { var dataURL = fr.result; component.set("v.pictureSrc", dataURL); helper.upload(component, file, dataURL.match(/,(.*)$/)[1],helper,event); }; fr.readAsDataURL(file); },
Best Answer chosen by Joseph Murawski
Joseph Murawski
I did not find THE answer, but I implemented lightning:Input type="File" instead of Input type="File" and it seems to have fixed the issue.