-
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
Top Sales Challenges in 2023 Which Salesforce Sales Cloud Can Solve
There’s no denying the fact that a sales job is full of challenges. Sales managers are constantly on the lookout for ways to optimize their…
noKodr as Rapid Prototype Solution to Business in 2024
Introduction In today's fast-paced world, businesses need to quickly validate their ideas and concepts before investing significant time and resources into development. This is where…
Successful Implementation Of Salesforce Communities
Salesforce Communities has changed the way businesses can handle connections with their customers, partners, and employees. The communities relevant to the industry can be created…
Popular Salesforce Videos
How to Configure SAML Single Sign-On with Salesforce as the Identity Provider
Configure single sign-on with a Salesforce org as the identity provider for an external Heroku app acting as the service provider, using SAML. Watch this…
Signing Up for a Free Salesforce Account
From Salesforce instructor, Become a Salesforce Expert. Sign up for a free Salesforce account and learn more about this technology. Mike Wheeler - http://mikewheelermedia.com
Salesforce Apex Tutorial: Data Types
In this lesson, we are covering Salesforce Apex Data Types and we are covering primitive data types.