-
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
Explore The Application Network | Salesforce Developer Guide
Let’s Find Why Is Integration So Challenging? The Fourth(4th) technological revolution is upon us. Connectivity across people, applications, data, and therefore the Internet of Things…
How to connect multiple accounts to single contact in Salesforce?
Setups to connect contacts to multiple accounts is quite easy and quick. Following are the steps to be followed: Go to Setup, enter Account Settings…
7 Most Common Questions About Salesforce Certifications
Salesforce certifications mark the first major milestone in a Salesforce professional’s career. They are great for power users that are looking to dive into Salesforce’s…
Popular Salesforce Videos
Basics of Salesforce Flow in 15 minutes
In this video, Jitendra Zaa gives a detailed overview of the basics of Salesforce Flow in just 15 minutes. He covers everything from how to…
In App Guidance | Salesforce Tutotial
In this video, we take a look at one of the new features from the Salesforce Summer '19 release - In-App Guidance. We explain what…
Guided Setup with Salesforce Field Service Administration - Webinar Recording
Salesforce Field Service is a complete, end-to-end solution for customer service in the field. Salesforce Field Service brings together customers, employees, and products on a…