-
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
![](https://images.forcetalks.com/wp-content/uploads/2021/05/25122320/sa_1621945291SalesforceCustomizationUser01.jpg)
How DemandBlue Empowered a Non-Profit Property Developer with Salesforce Customization
Why use Salesforce Sales Cloud Salesforce’s Sales Cloud is a top-rated CRM software that helps firms integrate information about leads, sales, and customers and access…
![Salesforce Data Loader](https://images.forcetalks.com/wp-content/uploads/2022/06/05150539/Salesforce-Data-Loader.jpg)
Salesforce Data Loader Guide - Here's All You Need to Know
Data Loader It is a Client Application used for importing and exporting bulk data. Using it we can Insert, Delete, Update, Upsert, and export the…
![](https://images.forcetalks.com/wp-content/uploads/2021/09/21072635/sa_1632209168PardotTracking01-1024x535.jpg)
The Fall of the Third Party Cookie: Here’s What Salesforce Pardot Users Need to Know
Marketers rely on cookies (the kind you cannot eat) to track visitor data and personalize marketing efforts. And like Cookie Monster love them. Google’s recent…
Popular Salesforce Videos
Salesforce Certification Registration, Check and Verify Certification Status, Trailblazer.me Profile
All About Salesforce Certification:- Schedule your Salesforce Certification Exam Link Your Salesforce Certifications to Your Trailblazer.me Profile Check & Verify Your Salesforce Certification & Maintenance…
Marc Benioff talks Salesforce - AT&T deal, office health safety and online media regulation
Salesforce’s Customer 360 will enable AT&T to deliver highly-tailored customer experiences seamlessly across retail, marketing, online, business, and more. AT&T will utilize Salesforce’s entire portfolio…
Learn About the Before Trigger in Salesforce Flows
Here I am creating 2 scenarios for before - Save Updates in Salesforce Flows Salesforce Summer '20 Flow Builder feature. Creating or updating a record…