-
My component is not working in Update
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes" controller="AccountSearchController">
<aura:attribute name="searchKeyword" type="String" default=""/>
<aura:attribute name="lstOfAccount" type="Account[]"/>
<aura:attribute name="listcontact" type="Contact[]"/>
<aura:attribute name="columns" type="List"/>
<aura:attribute name="isBlank" type="boolean" default="false"/>
<aura:attribute name="recordId" type="String"/>
<aura:attribute name="updatedRecord" type="Object[]" /><div class="slds-m-around_medium" style="background:#fff">
<lightning:layout>
<lightning:layoutItem padding="around-small">
<lightning:spinner variant="brand" size="medium" aura:id="Id_spinner" class="slds-hide" />
<h1 class="slds-page-header__title slds-truncate slds-align-middle"
title="Enter Account Name">Enter Account Name</h1>
<lightning:input value="{!v.searchKeyword}" required="true" aura:id="searchKeyword"/>
</lightning:layoutItem>
</lightning:layout><lightning:layout>
<lightning:layoutItem size="2" padding="around-small">
<lightning:button onclick="{!c.Search}" variant="brand" label="Search" iconName="utility:search"/>
</lightning:layoutItem>
</lightning:layout>
<aura:if isTrue="{!and(v.isBlank, v.lstOfAccount!=NULL)}">
<lightning:card title="Account Records" variant="brand">
<lightning:datatable columns="{! v.columns }" data="{!v.lstOfAccount}"
hideCheckboxColumn="true" keyField="Id" onsave ="{!c.Save}"/>
</lightning:card>
</aura:if>
</div>
</aura:component>
({
Search : function(component, event, helper) {
component.set('v.columns', [
{label: 'Name', fieldName: 'Name', editable:'true', type: 'text'},
{label: 'Phone', fieldName: 'Phone', editable:'true', type: 'Phone'},
{label: 'Industry', fieldName: 'Industry', editable:'true', type: 'text'}]);
var action = component.get("c.fetchAccount");
action.setParams({
"searchKeyWord" : component.get("v.searchKeyword")
});
action.setCallback(this, function(response) {
var state = response.getState();
if (state === "SUCCESS") {
component.set("v.lstOfAccount", response.getReturnValue());
component.set("v.isBlank",true);
if(response.getReturnValue()==null){
var toast = $A.get("e.force:showToast");
toast.setParams({
"type":"Error",
"title":"Error",
"message":"No Account Found",
"duration":1000
});
toast.fire();
}
}
});
$A.enqueueAction(action);
},
Save : function (component,event,helper){
var action=component.get("c.saveAccount");
action.setParams({
"AccListStr":JSON.stringify(component.get("v.lstOfAccount"))
});
action.setCallback(this, function(response) {
var state = response.getState();
if (component.isValid() && state === "SUCCESS") {
component.set("v.lstOfAccount", response.getReturnValue());
alert(response.getReturnValue());
var toast = $A.get("e.force:showToast");
toast.setParams({
"type":"Success",
"title":"Success",
"message":"Account Saved Successfully",
"duration":1000
});
toast.fire();
}
});
$A.enqueueAction(action);
}
})
public class AccountSearchController{@AuraEnabled
public static List <Account> fetchAccount(String searchKeyWord) {
String searchKey = searchKeyWord +'%';
List <Account> lstOfAccount = [SELECT Id, Name,Phone,Industry FROM Account
WHERE Name LIKE:searchKey];system.debug('==>'+lstOfAccount);
if(lstOfAccount.size() > 0)
return lstOfAccount;
else return null;
}
@auraEnabled
public static List<Account> saveAccount(String AccListStr){
List<Account> accList = (List<Account>)json.deserialize(AccListStr, List<Account>.class);
update accList;
system.debug('===>accList'+accList);
return accList;
}
}
Log In to reply.
Popular Salesforce Blogs

Specific Differences In Salesforce
WhoId Vs WhatId WhoId WhatId WhoId represents the person type things. WhatId represents object type things. LeadId and ContactId are categorized under the whoId. WhatId…

Salesforce could Make Big Data easy for both Businesses and Developers
Big data analytics is no longer a mystery that each and every IT guru uses in a conference. It is now a common tool deployed…

How to Effectively Manage Ideas on Salesforce Experience Cloud
The idea-creation process is a journey with many twists and turns. Ideas can be born in a flash, then bounce around for days or weeks…
Popular Salesforce Videos
All About Salesforce Web Chat
Salesforce webchat help customer interacts with the support team. It also improves the support experience for customers. It is very easy to set up the…
Salesforce Lightning Tutorial | Salesforce Training | Lightning Training Video
This Salesforce Lightning Tutorial will explain the concept of lightning components along with the lightning component capabilities. Lightning includes the Lightning Component Framework and some…
Code Review in Salesforce
Code Review and Code Quality in Salesforce 0:00 Introduction 0:44 What is code review? 1:22 Why we need code review 3:33 Basic code review 4:12…