I am new to lightning components and am trying to get a button in lightning to update a checkbox on a contact record(Send_to_IFS__c) when the button is clicked. Below is what i have but it is not updating the field or exiting the quick action. Any help or a point in the right direction would be appreciated
CMP
<aura:component implements="force:lightningQuickActionWithoutHeader,force:hasRecordId" >
<aura:attribute name="contact" type="Object"/>
<aura:attribute name="contactRecord" type="Object" default="{'sobjectType':'Contact', 'Send_to_IFS__c' : ''}"/>
<aura:attribute name="recordSaveError" type="String" description="An error message bound to force:recordData"/>
<force:recordData aura:id="conRec"
fields="Send_to_IFS__c"
recordId="{!v.recordId}"
targetError="{!v.recordSaveError}"
targetRecord="{!v.contact}"
targetFields="{!v.contactRecord}"
mode="EDIT"
/>
<aura:handler name="init" value="{!this}" action="{!c.handleClick}"/>
<aura:if isTrue="{!not(empty(v.recordSaveError))}">
<br />
<div class="error slds-box">
{!v.recordSaveError}
</div>
</aura:if>
</aura:component>
Controller
({
handleClick: function(component, event, helper){
helper.saveContact(component, event, helper);
},
recordUpdated : function(component, event, helper) {
helper.recordUpdated(component, event, helper);
}
})
Helper
({
saveContact : function(component, event, helper) {
component.set("v.contactRecord.Send_to_IFS__c", true);
component.find("conRec").saveRecord($A.getCallback(function(saveResult) {
if (saveResult.state === "SUCCESS" || saveResult.state === "DRAFT") {
alert("Save completed successfully.");
} else if (saveResult.state === "INCOMPLETE") {
component.set("v.recordSaveError","User is offline, device doesn't support drafts.");
} else if (saveResult.state === "ERROR") {
var errMsg = "";
// saveResult.error is an array of errors,
// so collect all errors into one message
for (var i = 0; i < saveResult.error.length; i++) {
errMsg += saveResult.error[i].message + "\n";
}
component.set("v.recordSaveError", errMsg);
} else {
component.set("v.recordSaveError",'Unknown problem, state: ' + saveResult.state + ', error: ' +
JSON.stringify(saveResult.error));
}
}));
$A.get("e.force:closeQuickAction").fire();
},
recordUpdated : function(component, event, helper){
var changeType = event.getParams().changeType;
if (changeType === "CHANGED") {
component.find("conRec").reloadRecord();
}
}
})