0

When I'm uploading an attachment every time, on Clicking of the Save button which calls the function using javascript in Lightning Component, it creates an Instance of an Object whose ParentId I'm considering for Attachment and a single Attachment is getting uploaded to Notes & Attachment related List. What I want in a single run all the attachments should be placed inside a single Instance of Object.

Public static account temp = new account();

@AuraEnabled
public static Id saveTheFile(Id parentId, String fileName, String base64Data, String contentType) { 
    system.debug('Before method call');
    base64Data = EncodingUtil.urlDecode(base64Data, 'UTF-8');

    system.debug('saveTheFile method call');

    update temp;
    system.debug('TEMP ID === ' + temp.id);
    Attachment addAtt = new Attachment();
    addAtt.Body = EncodingUtil.base64Decode(base64Data);
    addAtt.ParentId = temp.Id;
    addAtt.Name = fileName;
    addAtt.ContentType = contentType;

    attList.add(addAtt);
    insert attList;

    return attList[0].id;
}
1

This line:

Public static account temp = new account();

Will create an Account each time you press the button.

You need to return the Account.ID so that the following uses of the button use the same account record ID as the first time the button was pressed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.