You need to sign in to do that
Don't have an account?
Zane Prater 15
Could someone help with the lightning button in my controller, getting error: Uncaught Action failed: c:AccConAddressChange$controller$updateCheck11 [c is not defined]?
Simple requirement: Button that checks a boolean field (synch__c) on all contacts.
APEX CLASS
______________________________________________________
public with sharing class AccountContactAddressChange
{
@AuraEnabled
public static list<Contact> getRelatedList(Id recordId)
{
List<Contact> Conlist = [Select id,firstname,lastname,MailingCity,
MailingState,MailingPostalCode,account.billingaddress, synch__c
from Contact where AccountId =: recordId ];
return Conlist;
}
@AuraEnabled
public static void updateRelatedList(List<Contact> Conlist)
{
if(Conlist!= null && Conlist.size()>0)
{
update Conlist;
}
}
@AuraEnabled
public static void UpdateCheck(List<Contact> Conlist) {
For(Contact c:Conlist) {
c.Synch__c=true;
}
update Conlist;
}
}
COMPONENT
_______________________________________________________
<aura:component controller = "AccountContactAddressChange" implements="flexipage:availableForRecordHome,force:hasRecordId" access="global" >
<aura:attribute name="recordId" type="Id" />
<aura:attribute name="ContactList" type="Contact[]" />
<aura:attribute name="columns" type="List"/>
<aura:attribute name="UpdatedList" type="Contact[]"/>
<aura:handler name="init" value="{!this}" action="{!c.RetrieveData}" />
<lightning:card iconName="standard:work_capacity_usage" title="Synch Address">
<div class="slds-align_absolute-center" style="height:5rem">
<button class="slds-button slds-button_brand " onclick="{!c.updateCheck11}">Synch</button></div>
<aura:if isTrue="{!not(empty(v.ContactList))}">
<lightning:datatable data="{!v.ContactList }"
columns="{!v.columns }"
keyField="Id"
draftValues= "{!v.UpdatedList}"
onsave="{!c.SaveUpdatedContacts}"
hideCheckboxColumn="true"/>
<aura:set attribute="else">
<div Style="text-align : center"> " There are no related contacts "</div>
</aura:set>
</aura:if>
</lightning:card>
</aura:component>
JS CONTROLLER
_______________________________________________________
({
RetrieveData : function(component, event, helper)
{
component.set('v.columns', [
{label: 'First Name', fieldName: 'FirstName', type: 'text'},
{label: 'Last Name', fieldName: 'LastName', type: 'text'},
{label: 'City', fieldName: 'MailingCity', type: 'string'},
{label: 'State', fieldName: 'MailingState', type: 'string'},
{label: 'Zipcode', fieldName: 'MailingPostalCode', type: 'string'},
{label: 'Synch', fieldName: 'Synch__c', type: 'boolean', editable: true}
]);
var ConList = component.get("c.getRelatedList");
ConList.setParams
({
recordId: component.get("v.recordId")
});
ConList.setCallback(this, function(data)
{
component.set("v.ContactList", data.getReturnValue());
});
$A.enqueueAction(ConList);
},
SaveUpdatedContacts : function(component,event,helper)
{
var UpdatedList = event.getParam('draftValues');
var UpdateContacts = component.get("c.updateRelatedList");
UpdateContacts.setParams
({
Conlist : UpdatedList
});
UpdateContacts.setCallback(this, function(response)
{
var state = response.getState();
if (state === 'SUCCESS')
{
$A.enqueueAction(component.get('c.RetrieveData'));
$A.get('e.force:refreshView').fire();
}
else{
//error handling
}
});
$A.enqueueAction(UpdateContacts);
},
updateCheck11 : function(component, event, helper)
{
helper.updateCheck11_helper(component,event,helper);
}
}
)
HELPER
_______________________________________________________
({
updateCheck11_helper : function(component, event, helper) {
alert('sdfsd');
var save_action = c.get("c.updateCheck11");
save_action.setParams({
});
$A.enqueueAction(save_action);
}
})
APEX CLASS
______________________________________________________
public with sharing class AccountContactAddressChange
{
@AuraEnabled
public static list<Contact> getRelatedList(Id recordId)
{
List<Contact> Conlist = [Select id,firstname,lastname,MailingCity,
MailingState,MailingPostalCode,account.billingaddress, synch__c
from Contact where AccountId =: recordId ];
return Conlist;
}
@AuraEnabled
public static void updateRelatedList(List<Contact> Conlist)
{
if(Conlist!= null && Conlist.size()>0)
{
update Conlist;
}
}
@AuraEnabled
public static void UpdateCheck(List<Contact> Conlist) {
For(Contact c:Conlist) {
c.Synch__c=true;
}
update Conlist;
}
}
COMPONENT
_______________________________________________________
<aura:component controller = "AccountContactAddressChange" implements="flexipage:availableForRecordHome,force:hasRecordId" access="global" >
<aura:attribute name="recordId" type="Id" />
<aura:attribute name="ContactList" type="Contact[]" />
<aura:attribute name="columns" type="List"/>
<aura:attribute name="UpdatedList" type="Contact[]"/>
<aura:handler name="init" value="{!this}" action="{!c.RetrieveData}" />
<lightning:card iconName="standard:work_capacity_usage" title="Synch Address">
<div class="slds-align_absolute-center" style="height:5rem">
<button class="slds-button slds-button_brand " onclick="{!c.updateCheck11}">Synch</button></div>
<aura:if isTrue="{!not(empty(v.ContactList))}">
<lightning:datatable data="{!v.ContactList }"
columns="{!v.columns }"
keyField="Id"
draftValues= "{!v.UpdatedList}"
onsave="{!c.SaveUpdatedContacts}"
hideCheckboxColumn="true"/>
<aura:set attribute="else">
<div Style="text-align : center"> " There are no related contacts "</div>
</aura:set>
</aura:if>
</lightning:card>
</aura:component>
JS CONTROLLER
_______________________________________________________
({
RetrieveData : function(component, event, helper)
{
component.set('v.columns', [
{label: 'First Name', fieldName: 'FirstName', type: 'text'},
{label: 'Last Name', fieldName: 'LastName', type: 'text'},
{label: 'City', fieldName: 'MailingCity', type: 'string'},
{label: 'State', fieldName: 'MailingState', type: 'string'},
{label: 'Zipcode', fieldName: 'MailingPostalCode', type: 'string'},
{label: 'Synch', fieldName: 'Synch__c', type: 'boolean', editable: true}
]);
var ConList = component.get("c.getRelatedList");
ConList.setParams
({
recordId: component.get("v.recordId")
});
ConList.setCallback(this, function(data)
{
component.set("v.ContactList", data.getReturnValue());
});
$A.enqueueAction(ConList);
},
SaveUpdatedContacts : function(component,event,helper)
{
var UpdatedList = event.getParam('draftValues');
var UpdateContacts = component.get("c.updateRelatedList");
UpdateContacts.setParams
({
Conlist : UpdatedList
});
UpdateContacts.setCallback(this, function(response)
{
var state = response.getState();
if (state === 'SUCCESS')
{
$A.enqueueAction(component.get('c.RetrieveData'));
$A.get('e.force:refreshView').fire();
}
else{
//error handling
}
});
$A.enqueueAction(UpdateContacts);
},
updateCheck11 : function(component, event, helper)
{
helper.updateCheck11_helper(component,event,helper);
}
}
)
HELPER
_______________________________________________________
({
updateCheck11_helper : function(component, event, helper) {
alert('sdfsd');
var save_action = c.get("c.updateCheck11");
save_action.setParams({
});
$A.enqueueAction(save_action);
}
})
({
updateCheck11_helper : function(component, event, helper) {
alert('sdfsd');
var save_action = component.get("c.updateCheck11"); //this should be a Apex method. I guess it should be c.UpdateCheck
save_action.setParams({
});
$A.enqueueAction(save_action);
}
})
also make sure it is
var save_action = component.get("c.xxxx");
instead of
var save_action = c.get("c.xxxx");
CLASS:
@AuraEnabled
public static void UpdateCheck(List<Contact> Conlist) {
For(Contact c:Conlist) {
c.Synch__c=true;
conlist.add(c);
}
update Conlist;
}
COMPONENT:
<button class="slds-button slds-button_brand " onclick="{!c.updateCheck11}">Synch</button></div>
CONTROLLER:
updateCheck11 : function(component, event, helper)
{
helper.updateCheck11_helper(component,event,helper);
}
HELPER:
({
updateCheck11_helper : function(component, event, helper) {
alert('sdfsd');
var save_action = component.get("c.UpdateCheck");
save_action.setParams({
});
$A.enqueueAction(save_action);
}
})
Then it could be cache issue.
Can you try to disable cache for Lightning in Session Settings? or just refresh the browser a couple of times?
({
updateCheck11_helper : function(component, event, helper) {
alert('Are you sure you want to update addresses?');
var save_action = component.get("c.UpdateCheck");
let params = {};
params.Conlist = [];
save_action.setParams({"Conlist" : component.get("v.UpdatedList")
});
$A.enqueueAction(save_action);
}
})