-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
4Questions
-
0Replies
Invalid key Error
Hi,
Can anyone please let me know where exactly I am going wrong
I facing following error
This page has an error. You might just need to refresh it. Action failed: c:TestUpdateComponent$controller$editAccount [Invalid key saveAccountList] Failing descriptor: {c:TestUpdateComponent$controller$editAccount}
Here is my code :
apex class
public class TestUpdateController {
@AuraEnabled
public static List<Account> getAccListApex(List<Id> accountIds){
List<Account> accList = new List<Account>();
accList = [Select Id,Name, Type, Website,Phone,Industry from account limit 5];
return accList;
}
@AuraEnabled
Public static Map<String,String> saveAccountList(List<Account> accLists){
Map<String,String> resultMap = new Map<String,String>();
try{
update accLists;
resultMap.put('status','success');
resultMap.put('message','Account updated Sucessfully');
}
catch(Exception e){
resultMap.put('status','error');
resultMap.put('message',e.getMessage());
}
return resultMap;
}
}
------------------------------------------------------------------------------------
({
getAccountListhelper : function(component) {
//add action to global action queue and that action will get Apex controller and fetch list
var action = component.get("c.getAccListApex");
action.setParams({accountIds : component.get("v.recordId")});
action.setCallback(this,function(response){
var state = response.getState();
if(state === 'SUCCESS') {
console.log("====response====",response.getReturnValue());
component.set("v.accountList",response.getReturnValue());
}
else {
alert('Error in getting data');
}
});
// Adding the action variable to the global action queue
$A.enqueueAction(action);
},
saveAccount: function(component, event, helper){
var accList = component.get('v.accountList');
var recordViewForm = component.find('recordViewForm');
var recordEditForm = component.find('recordEditForm');
var saveAction = component.get('saveAccountList');
var btn = event.getSource();
var name = btn.get('v.name');
var toastEvent = $A.get("e.force:showToast");
saveAction.setParams({accLists: accList});
saveAction.setCallback(this,function(response){
if(state === 'SUCCESS') {
var dataMap = response.getReturnValue();
if(dataMap.status=='success'){
$A.util.addClass(recordEditForm,'formHide');
$A.util.removeClass(recordViewForm,'formHide');
btn.set('v.name','edit');
btn.set('v.label','Edit');
toastEvent.setParams({
"title": "Success!",
"message": "Account updated Successfully!"
});
toastEvent.fire();
}
else if(dataMap.status=='error'){
toastEvent.setParams({
"title": "Error!",
"message": "Error!"
});
toastEvent.fire();
}
}
else {
alert('Error in updating data');
}
});
$A.enqueueAction(saveAction);
}
})
----------------------------------------------------------------------------------
controller
({
getAccountList : function(component, event, helper) {
helper.getAccountListhelper(component);
},
createRecord : function (component, event, helper) {
//global action only work under one app container
alert('in global action');
var createRecordEvent = $A.get("e.force:createRecord");
createRecordEvent.setParams({
"entityApiName": "Account",
"defaultFieldValues":{
'AccountId':component.get("v.recordId")
}
});
createRecordEvent.fire();
} ,
editAccount:function(component, event, helper) {
//give refrence to button
var btn = event.getSource();
var name = btn.get('v.name');
// Getting the record view form and the record edit form elements
var recordViewForm = component.find('recordViewForm');
var recordEditForm = component.find('recordEditForm');
if(name=='edit') {
$A.util.addClass(recordViewForm,'formHide');
$A.util.removeClass(recordEditForm,'formHide');
btn.set('v.name','save');
btn.set('v.label','Save');
}
else if(name=='save') {
// Calling save if the button is save
helper.saveAccount(component, event, helper);
}
}
})
-----------------------------------------------------------------------------------
component
<aura:component implements="flexipage:availableForAllPageTypes,force:hasRecordId" controller="TestUpdateController" access="global">
<aura:attribute type="List" name="accountList"/>
<aura:handler name="init" action="{!c.getAccountList}" value="{!this}" />
<lightning:card title="Account">
<p class="slds-p-horizontal_small">
<div aura:id="recordViewForm">
<aura:iteration items="{!v.accountList}" var="account">
<lightning:recordViewForm recordId="{!account.Id}" objectApiName="Account">
<div class="slds-box slds-theme_default">
<lightning:outputField fieldName="Name" />
<lightning:outputField fieldName="Website" />
<lightning:outputField fieldName="Phone" />
<lightning:outputField fieldName="Type" />
</div>
</lightning:recordViewForm>
<br />
</aura:iteration>
</div>
<div aura:id="recordEditForm" class="formHide">
<aura:iteration items="{!v.accountList}" var="account">
<lightning:recordEditForm recordId="{!account.Id}" objectApiName="Account">
<lightning:inputField fieldName="Name" />
<lightning:inputField fieldName="Website" />
<lightning:inputField fieldName="Phone" />
<lightning:inputField fieldName="Type" />
</lightning:recordEditForm>
</aura:iteration>
</div>
</p>
<aura:set attribute="actions">
<lightning:button label="New" onclick="{!c.createRecord}"/>
<lightning:button variant="brand" label="Edit" name="edit" onclick="{!c.editAccount}"/>
</aura:set>
</lightning:card>
</aura:component>
----------------------------------------------------------------------------
Can anyone please let me know where exactly I am going wrong
I facing following error
This page has an error. You might just need to refresh it. Action failed: c:TestUpdateComponent$controller$editAccount [Invalid key saveAccountList] Failing descriptor: {c:TestUpdateComponent$controller$editAccount}
Here is my code :
apex class
public class TestUpdateController {
@AuraEnabled
public static List<Account> getAccListApex(List<Id> accountIds){
List<Account> accList = new List<Account>();
accList = [Select Id,Name, Type, Website,Phone,Industry from account limit 5];
return accList;
}
@AuraEnabled
Public static Map<String,String> saveAccountList(List<Account> accLists){
Map<String,String> resultMap = new Map<String,String>();
try{
update accLists;
resultMap.put('status','success');
resultMap.put('message','Account updated Sucessfully');
}
catch(Exception e){
resultMap.put('status','error');
resultMap.put('message',e.getMessage());
}
return resultMap;
}
}
------------------------------------------------------------------------------------
({
getAccountListhelper : function(component) {
//add action to global action queue and that action will get Apex controller and fetch list
var action = component.get("c.getAccListApex");
action.setParams({accountIds : component.get("v.recordId")});
action.setCallback(this,function(response){
var state = response.getState();
if(state === 'SUCCESS') {
console.log("====response====",response.getReturnValue());
component.set("v.accountList",response.getReturnValue());
}
else {
alert('Error in getting data');
}
});
// Adding the action variable to the global action queue
$A.enqueueAction(action);
},
saveAccount: function(component, event, helper){
var accList = component.get('v.accountList');
var recordViewForm = component.find('recordViewForm');
var recordEditForm = component.find('recordEditForm');
var saveAction = component.get('saveAccountList');
var btn = event.getSource();
var name = btn.get('v.name');
var toastEvent = $A.get("e.force:showToast");
saveAction.setParams({accLists: accList});
saveAction.setCallback(this,function(response){
if(state === 'SUCCESS') {
var dataMap = response.getReturnValue();
if(dataMap.status=='success'){
$A.util.addClass(recordEditForm,'formHide');
$A.util.removeClass(recordViewForm,'formHide');
btn.set('v.name','edit');
btn.set('v.label','Edit');
toastEvent.setParams({
"title": "Success!",
"message": "Account updated Successfully!"
});
toastEvent.fire();
}
else if(dataMap.status=='error'){
toastEvent.setParams({
"title": "Error!",
"message": "Error!"
});
toastEvent.fire();
}
}
else {
alert('Error in updating data');
}
});
$A.enqueueAction(saveAction);
}
})
----------------------------------------------------------------------------------
controller
({
getAccountList : function(component, event, helper) {
helper.getAccountListhelper(component);
},
createRecord : function (component, event, helper) {
//global action only work under one app container
alert('in global action');
var createRecordEvent = $A.get("e.force:createRecord");
createRecordEvent.setParams({
"entityApiName": "Account",
"defaultFieldValues":{
'AccountId':component.get("v.recordId")
}
});
createRecordEvent.fire();
} ,
editAccount:function(component, event, helper) {
//give refrence to button
var btn = event.getSource();
var name = btn.get('v.name');
// Getting the record view form and the record edit form elements
var recordViewForm = component.find('recordViewForm');
var recordEditForm = component.find('recordEditForm');
if(name=='edit') {
$A.util.addClass(recordViewForm,'formHide');
$A.util.removeClass(recordEditForm,'formHide');
btn.set('v.name','save');
btn.set('v.label','Save');
}
else if(name=='save') {
// Calling save if the button is save
helper.saveAccount(component, event, helper);
}
}
})
-----------------------------------------------------------------------------------
component
<aura:component implements="flexipage:availableForAllPageTypes,force:hasRecordId" controller="TestUpdateController" access="global">
<aura:attribute type="List" name="accountList"/>
<aura:handler name="init" action="{!c.getAccountList}" value="{!this}" />
<lightning:card title="Account">
<p class="slds-p-horizontal_small">
<div aura:id="recordViewForm">
<aura:iteration items="{!v.accountList}" var="account">
<lightning:recordViewForm recordId="{!account.Id}" objectApiName="Account">
<div class="slds-box slds-theme_default">
<lightning:outputField fieldName="Name" />
<lightning:outputField fieldName="Website" />
<lightning:outputField fieldName="Phone" />
<lightning:outputField fieldName="Type" />
</div>
</lightning:recordViewForm>
<br />
</aura:iteration>
</div>
<div aura:id="recordEditForm" class="formHide">
<aura:iteration items="{!v.accountList}" var="account">
<lightning:recordEditForm recordId="{!account.Id}" objectApiName="Account">
<lightning:inputField fieldName="Name" />
<lightning:inputField fieldName="Website" />
<lightning:inputField fieldName="Phone" />
<lightning:inputField fieldName="Type" />
</lightning:recordEditForm>
</aura:iteration>
</div>
</p>
<aura:set attribute="actions">
<lightning:button label="New" onclick="{!c.createRecord}"/>
<lightning:button variant="brand" label="Edit" name="edit" onclick="{!c.editAccount}"/>
</aura:set>
</lightning:card>
</aura:component>
----------------------------------------------------------------------------
- Vishakha Soman
- May 28, 2021
- Like
- 0
Error : Assertion Failed!
Hi,
I am facing the following error while updating the records.
Assertion Failed!: Unable to set value for key 'c.updateAccount'. Value provider does not implement 'set(key, value)'. : false Failing descriptor: {markup://c:TestUpdateComponent}
How will I set the Key can anyone please help
code :
Apex class:
public class TestUpdateController {
@AuraEnabled
public static List<Account> getAccListApex(List<Id> accountIds){
List<Account> accList = new List<Account>();
accList = [Select Id,Name, Type, Website,Phone,Industry from account limit 5];
return accList;
}
Public static void updateAccount(string name, string website, string phone, string type){
Account acc = new Account();
acc.name = name;
acc.website = website;
acc.Phone = phone;
acc.type = type;
update acc;
}
}
================================================
helper
({
getAccountListhelper : function(component) {
//add action to global action queue and that action will get Apex controller and fetch list
var action = component.get("c.getAccListApex");
action.setParams({accountIds : component.get("v.recordId")});
action.setCallback(this,function(response){
var state = response.getState();
if(state === 'SUCCESS') {
console.log("====response====",response.getReturnValue());
component.set("v.accountList",response.getReturnValue());
}
else {
alert('Error in getting data');
}
});
// Adding the action variable to the global action queue
$A.enqueueAction(action);
},
saveAccount : function(component, event, helper){
var action = component.set("c.updateAccount");
action.setParams({
name : component.set("v.Name"),
website:component.set("v.Website"),
Phone:component.set("v.Phone"),
type:component.set("v.Type")
});
action.setCallback(this,function(response){
var state = response.getState();
if(state === 'SUCCESS') {
console.log("====response====",response.getReturnValue());
component.set("v.accountList",response.getReturnValue());
}
else {
alert('Error in updating data');
}
});
// Adding the action variable to the global action queue
$A.enqueueAction(action);
}
})
----------------------------------------------------------------------------------
controller
({
getAccountList : function(component, event, helper) {
helper.getAccountListhelper(component);
},
createRecord : function (component, event, helper) {
//global action only work under one app container
alert('in global action');
var createRecordEvent = $A.get("e.force:createRecord");
createRecordEvent.setParams({
"entityApiName": "Account",
"defaultFieldValues":{
'AccountId':component.get("v.recordId")
}
});
createRecordEvent.fire();
} ,
editAccount : function(component, event, helper) {
//give refrence to button
var btn = event.getSource();
var name = btn.get('v.name');
// Getting the record view form and the record edit form elements
var recordViewForm = component.find('recordViewForm');
var recordEditForm = component.find('recordEditForm');
if(name=='edit') {
$A.util.addClass(recordViewForm,'formHide');
$A.util.removeClass(recordEditForm,'formHide');
btn.set('v.name','save');
btn.set('v.label','Save');
}
else if(name=='save') {
// Calling save if the button is save
helper.saveAccount(c<aura:component implements="flexipage:availableForAllPageTypes,force:hasRecordId" controller="TestUpdateController" access="global">
<aura:attribute type="List" name="accountList"/>
<aura:attribute name="Name" type="String" />
<aura:attribute name="Phone" type="String"/>
<aura:attribute name="Website" type="String" />
<aura:attribute name="type" type="String"/>
<aura:handler name="init" action="{!c.getAccountList}" value="{!this}" />
<lightning:card title="Account">
<p class="slds-p-horizontal_small">
<div aura:id="recordViewForm">
<aura:iteration items="{!v.accountList}" var="account">
<lightning:recordViewForm recordId="{!account.Id}" objectApiName="Account">
<div class="slds-box slds-theme_default">
<lightning:outputField fieldName="Name" />
<lightning:outputField fieldName="Website" />
<lightning:outputField fieldName="Phone" />
<lightning:outputField fieldName="Type" />
</div>
</lightning:recordViewForm>
<br />
</aura:iteration>
</div>
<div aura:id="recordEditForm" class="formHide">
<aura:iteration items="{!v.accountList}" var="account">
<lightning:recordEditForm recordId="{!account.Id}" objectApiName="Account">
<lightning:inputField fieldName="Name" />
<lightning:inputField fieldName="Website" />
<lightning:inputField fieldName="Phone" />
<lightning:inputField fieldName="Type" />
</lightning:recordEditForm>
</aura:iteration>
</div>
</p>
<aura:set attribute="actions">
<lightning:button label="New" onclick="{!c.createRecord}"/>
<lightning:button variant="brand" label="Edit" name="edit" onclick="{!c.editAccount}"/>
</aura:set>
</lightning:card>
</aura:component>omponent, event, helper);
}
}
})
----------------------------------------------------------------------------------------
Thankyou in Advance
I am facing the following error while updating the records.
Assertion Failed!: Unable to set value for key 'c.updateAccount'. Value provider does not implement 'set(key, value)'. : false Failing descriptor: {markup://c:TestUpdateComponent}
How will I set the Key can anyone please help
code :
Apex class:
public class TestUpdateController {
@AuraEnabled
public static List<Account> getAccListApex(List<Id> accountIds){
List<Account> accList = new List<Account>();
accList = [Select Id,Name, Type, Website,Phone,Industry from account limit 5];
return accList;
}
Public static void updateAccount(string name, string website, string phone, string type){
Account acc = new Account();
acc.name = name;
acc.website = website;
acc.Phone = phone;
acc.type = type;
update acc;
}
}
================================================
helper
({
getAccountListhelper : function(component) {
//add action to global action queue and that action will get Apex controller and fetch list
var action = component.get("c.getAccListApex");
action.setParams({accountIds : component.get("v.recordId")});
action.setCallback(this,function(response){
var state = response.getState();
if(state === 'SUCCESS') {
console.log("====response====",response.getReturnValue());
component.set("v.accountList",response.getReturnValue());
}
else {
alert('Error in getting data');
}
});
// Adding the action variable to the global action queue
$A.enqueueAction(action);
},
saveAccount : function(component, event, helper){
var action = component.set("c.updateAccount");
action.setParams({
name : component.set("v.Name"),
website:component.set("v.Website"),
Phone:component.set("v.Phone"),
type:component.set("v.Type")
});
action.setCallback(this,function(response){
var state = response.getState();
if(state === 'SUCCESS') {
console.log("====response====",response.getReturnValue());
component.set("v.accountList",response.getReturnValue());
}
else {
alert('Error in updating data');
}
});
// Adding the action variable to the global action queue
$A.enqueueAction(action);
}
})
----------------------------------------------------------------------------------
controller
({
getAccountList : function(component, event, helper) {
helper.getAccountListhelper(component);
},
createRecord : function (component, event, helper) {
//global action only work under one app container
alert('in global action');
var createRecordEvent = $A.get("e.force:createRecord");
createRecordEvent.setParams({
"entityApiName": "Account",
"defaultFieldValues":{
'AccountId':component.get("v.recordId")
}
});
createRecordEvent.fire();
} ,
editAccount : function(component, event, helper) {
//give refrence to button
var btn = event.getSource();
var name = btn.get('v.name');
// Getting the record view form and the record edit form elements
var recordViewForm = component.find('recordViewForm');
var recordEditForm = component.find('recordEditForm');
if(name=='edit') {
$A.util.addClass(recordViewForm,'formHide');
$A.util.removeClass(recordEditForm,'formHide');
btn.set('v.name','save');
btn.set('v.label','Save');
}
else if(name=='save') {
// Calling save if the button is save
helper.saveAccount(c<aura:component implements="flexipage:availableForAllPageTypes,force:hasRecordId" controller="TestUpdateController" access="global">
<aura:attribute type="List" name="accountList"/>
<aura:attribute name="Name" type="String" />
<aura:attribute name="Phone" type="String"/>
<aura:attribute name="Website" type="String" />
<aura:attribute name="type" type="String"/>
<aura:handler name="init" action="{!c.getAccountList}" value="{!this}" />
<lightning:card title="Account">
<p class="slds-p-horizontal_small">
<div aura:id="recordViewForm">
<aura:iteration items="{!v.accountList}" var="account">
<lightning:recordViewForm recordId="{!account.Id}" objectApiName="Account">
<div class="slds-box slds-theme_default">
<lightning:outputField fieldName="Name" />
<lightning:outputField fieldName="Website" />
<lightning:outputField fieldName="Phone" />
<lightning:outputField fieldName="Type" />
</div>
</lightning:recordViewForm>
<br />
</aura:iteration>
</div>
<div aura:id="recordEditForm" class="formHide">
<aura:iteration items="{!v.accountList}" var="account">
<lightning:recordEditForm recordId="{!account.Id}" objectApiName="Account">
<lightning:inputField fieldName="Name" />
<lightning:inputField fieldName="Website" />
<lightning:inputField fieldName="Phone" />
<lightning:inputField fieldName="Type" />
</lightning:recordEditForm>
</aura:iteration>
</div>
</p>
<aura:set attribute="actions">
<lightning:button label="New" onclick="{!c.createRecord}"/>
<lightning:button variant="brand" label="Edit" name="edit" onclick="{!c.editAccount}"/>
</aura:set>
</lightning:card>
</aura:component>omponent, event, helper);
}
}
})
----------------------------------------------------------------------------------------
Thankyou in Advance
- Vishakha Soman
- May 28, 2021
- Like
- 0
Update Account details using recordID
Hi,
I am trying to create a component which will update any account feild by fetching record details and update it using update button. But how will I acess record using recordID and display it as outputfeild.
and How will I set those values back.
It will really help if anyone can guide me with this.
Here is my code according to my knowledge:
Component.cmp
<aura:component implements="flexipage:availableForRecordHome, force:hasRecordId">
<aura:attribute name="recordId" type="Id" />
<aura:attribute type="List" name="accountList"/>
<aura:attribute name="name" type="string" />
<aura:attribute name="type" type="string" />
<aura:attribute name="phone" type="string" />
<aura:attribute name="website" type="string" />
<lightning:recordViewForm recordId="{!v.recordId}" objectApiName="Account">
<lightning:card title="Update Account">
<aura:set attribute="actions">
<lightning:button variant="brand" label="Update Account" title="Update Account" onclick="{!c.updateAccountController}" />
</aura:set>
<p class="slds-p-horizontal_small">
<div class="slds-grid slds-wrap">
<span class="slds-size_1-of-2">
<lightning:outputField name="outputAccountName" value="{!v.accountName}" label="Account Name"/>
</span>
<span class="slds-size_1-of-2 slds-p-left_x-small">
<lightning:outputField type="tel" label="Phone" name="phone1" value="{!v.phone}"/>
</span>
<span class="slds-size_1-of-2">
<lightning:outputField name="outputWebsite" label="Website" value="{!v.website}"/>
</span>
<span class="slds-size_1-of-2 slds-p-left_x-small">
<lightning:outputField name="outputType" label="Type" value="{!v.type}"/>
</span>
</div>
</p>
</lightning:card>
</lightning:recordViewForm>
</aura:component>
====================================================
controller.js
({
ChangeText : function(component, event, helper) {
helper.getAccountListHelper(component);
},
UpdateAccountController : function(component, event, helper) {
var action = component.get("c.UpdateAccountApex");
action.setParams({
accName : component.set("v.accountName"),
phone : component.set("v.phone"),
website : component.set("v.website"),
type : component.set("v.type")
})
action.setCallback(this,function(response){
var state = response.getState();
if(state === "SUCCESS"){
console.log("====response===="+response.getReturnValue());
var toastEvent = $A.get("e.force:showToast");
toastEvent.setParams({
"title": "Success!",
"message": "Account updated Successfully!"
});
toastEvent.fire();
}
else if(state === "ERROR"){
var toastEvent = $A.get("e.force:showToast");
toastEvent.setParams({
"title": "Error!",
"message": "An Error Occured!"
});
toastEvent.fire();
}
});
$A.enqueueAction(action);
}
})
===================================================
helper.js
({
getAccountListHelper: function(component) {
component.set('v.mycolumns',[
{label: 'Account Name' ,fieldName: 'Name',type: 'text', sortable:true},
{label: 'Account Type' ,fieldName: 'Type',type: 'text'},
{label: 'Website' ,fieldName: 'Website',type: 'url'},
{label: 'Phone' ,fieldName: 'Phone',type: 'Phone'},
]);
var action = component.get("c.getAccListApex");
action.setCallback(this,function(response){
var state = response.getState();
if (state == "SUCCESS")
{
console.log("====response====",response.getReturnValue());
component.set("v.accountList",response.getReturnValue());
}
if (state == "Error")
{
alert('error');
}
});
$A.enqueueAction(action);
}
====================================================
apexclass
public class TestControllerUpdateApex {
@AuraEnabled
public static List<Account> getAccListApex(){
List<Account> accList = new List<Account>();
accList = [Select Id,Name, Type, Website,Phone,Industry from account];
return accList;
}
@AuraEnabled
public static void UpdateAccountApex(string[] recordId){
List<Account> accList = [Select id from Account where id=:recordId];
update accList;
}
@AuraEnabled
public static string createAccountApex(string accName, string phone, string website, string type){
Account acc = new Account();
acc.name = accName;
acc.Phone = phone;
acc.website = website;
acc.type = type;
insert acc;
return acc.Id;
}
})
Thankyou in Advance
I am trying to create a component which will update any account feild by fetching record details and update it using update button. But how will I acess record using recordID and display it as outputfeild.
and How will I set those values back.
It will really help if anyone can guide me with this.
Here is my code according to my knowledge:
Component.cmp
<aura:component implements="flexipage:availableForRecordHome, force:hasRecordId">
<aura:attribute name="recordId" type="Id" />
<aura:attribute type="List" name="accountList"/>
<aura:attribute name="name" type="string" />
<aura:attribute name="type" type="string" />
<aura:attribute name="phone" type="string" />
<aura:attribute name="website" type="string" />
<lightning:recordViewForm recordId="{!v.recordId}" objectApiName="Account">
<lightning:card title="Update Account">
<aura:set attribute="actions">
<lightning:button variant="brand" label="Update Account" title="Update Account" onclick="{!c.updateAccountController}" />
</aura:set>
<p class="slds-p-horizontal_small">
<div class="slds-grid slds-wrap">
<span class="slds-size_1-of-2">
<lightning:outputField name="outputAccountName" value="{!v.accountName}" label="Account Name"/>
</span>
<span class="slds-size_1-of-2 slds-p-left_x-small">
<lightning:outputField type="tel" label="Phone" name="phone1" value="{!v.phone}"/>
</span>
<span class="slds-size_1-of-2">
<lightning:outputField name="outputWebsite" label="Website" value="{!v.website}"/>
</span>
<span class="slds-size_1-of-2 slds-p-left_x-small">
<lightning:outputField name="outputType" label="Type" value="{!v.type}"/>
</span>
</div>
</p>
</lightning:card>
</lightning:recordViewForm>
</aura:component>
====================================================
controller.js
({
ChangeText : function(component, event, helper) {
helper.getAccountListHelper(component);
},
UpdateAccountController : function(component, event, helper) {
var action = component.get("c.UpdateAccountApex");
action.setParams({
accName : component.set("v.accountName"),
phone : component.set("v.phone"),
website : component.set("v.website"),
type : component.set("v.type")
})
action.setCallback(this,function(response){
var state = response.getState();
if(state === "SUCCESS"){
console.log("====response===="+response.getReturnValue());
var toastEvent = $A.get("e.force:showToast");
toastEvent.setParams({
"title": "Success!",
"message": "Account updated Successfully!"
});
toastEvent.fire();
}
else if(state === "ERROR"){
var toastEvent = $A.get("e.force:showToast");
toastEvent.setParams({
"title": "Error!",
"message": "An Error Occured!"
});
toastEvent.fire();
}
});
$A.enqueueAction(action);
}
})
===================================================
helper.js
({
getAccountListHelper: function(component) {
component.set('v.mycolumns',[
{label: 'Account Name' ,fieldName: 'Name',type: 'text', sortable:true},
{label: 'Account Type' ,fieldName: 'Type',type: 'text'},
{label: 'Website' ,fieldName: 'Website',type: 'url'},
{label: 'Phone' ,fieldName: 'Phone',type: 'Phone'},
]);
var action = component.get("c.getAccListApex");
action.setCallback(this,function(response){
var state = response.getState();
if (state == "SUCCESS")
{
console.log("====response====",response.getReturnValue());
component.set("v.accountList",response.getReturnValue());
}
if (state == "Error")
{
alert('error');
}
});
$A.enqueueAction(action);
}
====================================================
apexclass
public class TestControllerUpdateApex {
@AuraEnabled
public static List<Account> getAccListApex(){
List<Account> accList = new List<Account>();
accList = [Select Id,Name, Type, Website,Phone,Industry from account];
return accList;
}
@AuraEnabled
public static void UpdateAccountApex(string[] recordId){
List<Account> accList = [Select id from Account where id=:recordId];
update accList;
}
@AuraEnabled
public static string createAccountApex(string accName, string phone, string website, string type){
Account acc = new Account();
acc.name = accName;
acc.Phone = phone;
acc.website = website;
acc.type = type;
insert acc;
return acc.Id;
}
})
Thankyou in Advance
- Vishakha Soman
- May 24, 2021
- Like
- 0
Error in $A.getCallback() [helper is not defined]
Hi,
I am facing the following error while deleting account from list :
Error in $A.getCallback() [helper is not defined]
My code is as follows:
Component.cmp
<aura:component controller="TestController ">
<!-- Attribute Section -->
<aura:attribute name="sortDirection" type="String" default="asc" />
<aura:attribute name="defaultSortDirection" type="String" default="asc" />
<aura:attribute name="sortedBy" type="String" />
<aura:attribute name="mycolumns" type="List"/>
<aura:attribute type="List" name="accountList"/>
<aura:attribute type="List" name="selectedAccountIds"/>
<!-- Handler Section -->
<aura:handler name="init" value="{!this}" action="{!c.ChangeText}"/>
<!-- Body -->
<lightning:button variant="destructive"
label="Delete Account"
title="Delete"
onclick="{!c.deleteAccount}"/>
<lightning:datatable data="{!v.accountList}"
columns="{!v.mycolumns}"
keyField="Id"
hideCheckboxColumn="false"
onrowselection="{!c.getSelectedName}"
defaultSortDirection="{!v.defaultSortDirection}"
sortedDirection="{!v.sortDirection}"
sortedBy="{!v.sortedBy}"
onsort="{!c.handleSort}"
/>
</aura:component>
==================================================
controller.js
({
ChangeText : function(component, event, helper) {
helper.getAccountListHelper(component);
},
getSelectedName:function(component, event, helper){
var my_ids = [];
var selectedRows = event.getParam("selectedRows");
for(var i=0; i< selectedRows.length; i++){
// alert('You Selected ID'+selectedRows[i].Id);
my_ids.push(selectedRows[i].Id);
}
component.set("v.selectedAccountIds",my_ids);
},
handleSort : function(cmp, event, helper) {
helper.handleSort(cmp,event);
},
deleteAccount: function(component, event, helper) {
helper.deleteAccountHelper(component, event, helper);
}
})
====================================================
helper.js
({
getAccountListHelper: function(component) {
component.set('v.mycolumns',[
{label: 'Account Name' ,fieldName: 'Name',type: 'text', sortable:true},
{label: 'Account Type' ,fieldName: 'Type',type: 'text'},
{label: 'Website' ,fieldName: 'Website',type: 'url'},
{label: 'Phone' ,fieldName: 'Phone',type: 'Phone'},
{label: 'Industry' ,fieldName: 'Industry',type: 'text'}
]);
var action = component.get("c.getAccListApex");
action.setCallback(this,function(response){
var state = response.getState();
if (state == "SUCCESS")
{
console.log("====response====",response.getReturnValue());
component.set("v.accountList",response.getReturnValue());
}
if (state == "Error")
{
alert('error');
}
});
$A.enqueueAction(action);
} ,
sortBy: function(field, reverse, primer) {
var key = primer
? function(x) {
return primer(x[field]);
}
: function(x) {
return x[field];
};
return function(a, b) {
a = key(a);
b = key(b);
return reverse * ((a > b) - (b > a));
};
},
handleSort: function(cmp, event) {
var sortedBy = event.getParam('fieldName');
var sortDirection = event.getParam('sortDirection');
var cloneData = cmp.get("v.accountList");
cloneData = cloneData.slice(0);
cloneData.sort((this.sortBy(sortedBy, sortDirection === 'asc' ? 1 : -1)));
cmp.set('v.accountList', cloneData);
cmp.set('v.sortDirection', sortDirection);
cmp.set('v.sortedBy', sortedBy);
},
deleteAccountHelper: function(component,event,Helper) {
var action = component.get("c.deleteAccountApex");
action.setParams({accIds : component.get("v.selectedAccountIds")});
action.setCallback(this,function(response){
var state = response.getState();
if (state == "SUCCESS")
{
helper.getAccountListHelper(component);
alert('Account Deleted Sucessfully');
}
if (state == "Error")
{
alert('error');
}
});
$A.enqueueAction(action);
}
})
====================================================
ApexClass
public class TestController {
@AuraEnabled
public static List<Account> getAccListApex(){
List<Account> acclist = new List<Account>();
acclist = [Select Id, Name, Type, Website, Phone, Industry from Account];
return acclist;
}
@AuraEnabled
public static void deleteAccountApex(List<string> accIds){
List<Account> acclist = [Select id from Account where id in: accIds];
delete acclist;
}
}
I am facing the following error while deleting account from list :
Error in $A.getCallback() [helper is not defined]
My code is as follows:
Component.cmp
<aura:component controller="TestController ">
<!-- Attribute Section -->
<aura:attribute name="sortDirection" type="String" default="asc" />
<aura:attribute name="defaultSortDirection" type="String" default="asc" />
<aura:attribute name="sortedBy" type="String" />
<aura:attribute name="mycolumns" type="List"/>
<aura:attribute type="List" name="accountList"/>
<aura:attribute type="List" name="selectedAccountIds"/>
<!-- Handler Section -->
<aura:handler name="init" value="{!this}" action="{!c.ChangeText}"/>
<!-- Body -->
<lightning:button variant="destructive"
label="Delete Account"
title="Delete"
onclick="{!c.deleteAccount}"/>
<lightning:datatable data="{!v.accountList}"
columns="{!v.mycolumns}"
keyField="Id"
hideCheckboxColumn="false"
onrowselection="{!c.getSelectedName}"
defaultSortDirection="{!v.defaultSortDirection}"
sortedDirection="{!v.sortDirection}"
sortedBy="{!v.sortedBy}"
onsort="{!c.handleSort}"
/>
</aura:component>
==================================================
controller.js
({
ChangeText : function(component, event, helper) {
helper.getAccountListHelper(component);
},
getSelectedName:function(component, event, helper){
var my_ids = [];
var selectedRows = event.getParam("selectedRows");
for(var i=0; i< selectedRows.length; i++){
// alert('You Selected ID'+selectedRows[i].Id);
my_ids.push(selectedRows[i].Id);
}
component.set("v.selectedAccountIds",my_ids);
},
handleSort : function(cmp, event, helper) {
helper.handleSort(cmp,event);
},
deleteAccount: function(component, event, helper) {
helper.deleteAccountHelper(component, event, helper);
}
})
====================================================
helper.js
({
getAccountListHelper: function(component) {
component.set('v.mycolumns',[
{label: 'Account Name' ,fieldName: 'Name',type: 'text', sortable:true},
{label: 'Account Type' ,fieldName: 'Type',type: 'text'},
{label: 'Website' ,fieldName: 'Website',type: 'url'},
{label: 'Phone' ,fieldName: 'Phone',type: 'Phone'},
{label: 'Industry' ,fieldName: 'Industry',type: 'text'}
]);
var action = component.get("c.getAccListApex");
action.setCallback(this,function(response){
var state = response.getState();
if (state == "SUCCESS")
{
console.log("====response====",response.getReturnValue());
component.set("v.accountList",response.getReturnValue());
}
if (state == "Error")
{
alert('error');
}
});
$A.enqueueAction(action);
} ,
sortBy: function(field, reverse, primer) {
var key = primer
? function(x) {
return primer(x[field]);
}
: function(x) {
return x[field];
};
return function(a, b) {
a = key(a);
b = key(b);
return reverse * ((a > b) - (b > a));
};
},
handleSort: function(cmp, event) {
var sortedBy = event.getParam('fieldName');
var sortDirection = event.getParam('sortDirection');
var cloneData = cmp.get("v.accountList");
cloneData = cloneData.slice(0);
cloneData.sort((this.sortBy(sortedBy, sortDirection === 'asc' ? 1 : -1)));
cmp.set('v.accountList', cloneData);
cmp.set('v.sortDirection', sortDirection);
cmp.set('v.sortedBy', sortedBy);
},
deleteAccountHelper: function(component,event,Helper) {
var action = component.get("c.deleteAccountApex");
action.setParams({accIds : component.get("v.selectedAccountIds")});
action.setCallback(this,function(response){
var state = response.getState();
if (state == "SUCCESS")
{
helper.getAccountListHelper(component);
alert('Account Deleted Sucessfully');
}
if (state == "Error")
{
alert('error');
}
});
$A.enqueueAction(action);
}
})
====================================================
ApexClass
public class TestController {
@AuraEnabled
public static List<Account> getAccListApex(){
List<Account> acclist = new List<Account>();
acclist = [Select Id, Name, Type, Website, Phone, Industry from Account];
return acclist;
}
@AuraEnabled
public static void deleteAccountApex(List<string> accIds){
List<Account> acclist = [Select id from Account where id in: accIds];
delete acclist;
}
}
- Vishakha Soman
- May 22, 2021
- Like
- 0