Can anyone help me with the code for attachments while creating account(record)as my code is not saving the record in salesforce lightning? Help will be appreciated.
<aura:registerEvent name="saveAttachment" type="c:fileUploadEvt"/>
Client Contract: <c:fileUpload aura:id="file1" />
Client Logo:<c:fileUpload aura:id="file2" />
Others:<c:fileUpload aura:id="file3" />
jscontroller
helper.getid(component);
jshelper
getid: function(component) {
var action = component.get("c.getid");
var ide;
action.setCallback(this, function(response) {
var state = response.getState();
console.debug("state"+state);
if (component.isValid() && state === "SUCCESS") {
component.set("v.id", response.getReturnValue());
//component.set("v.id",ide);
var id = component.get("v.id");
ide=id;
console.debug("id-->"+id);
console.debug("ide"+ide);
var id1=component.get("v.id");
console.debug("id1-->"+id1);
var updateEvent = component.getEvent("saveAttachment");
updateEvent.setParams({ "ParentId": id1 }).fire();
}
});
apex controller
public static string ide;
@AuraEnabled
Public static Id getid(){
return ide;
}
@AuraEnabled
public static Account saveAction(Account Acc) {
// Perform isUpdateable() check here
insert Acc;
ide = Acc.id;
system.debug(acc.id);
return Acc;
}
attachment event
<aura:event type="COMPONENT" description="Event template" >
<aura:attribute name="ParentId" type="Id"/>
<!--<aura:attribute name="Name" type="string"/>-->
</aura:event>
file attachment
<aura:attribute name="ParentId" type="Id" access="Global" default="{}"/>
<aura:handler name="saveAttachment" event="c:fileUploadEvt" action="{!c.save}"
<input type="file" class="file" aura:id="file" />
<!--<ui:button label="Save" press="{!c.save}"/>-->
file attachment js controller
save : function(component, event, helper) {
var parmid = event.getParam("ParentId");
component.set("v.ParentId", parmid);
var ParentId = component.get("v.ParentId");
console.debug("ParentId--->"+ParentId);
helper.save(component);
},
Note
i have followed this site to get save the file to attachment but i have created event to get id from component
and save functionality but it is not working
but indivdually its working
http://peterknolle.com/file-upload-lightning-component/
Could you please share the code, so that we can analyze what is going wrong with it.
Thanks,
Gaurav
skype: gaurav62990