You need to sign in to do that
Don't have an account?
Sudhaaaa
need to filter records using search button.
Hi,
From this below code i am getting list of accounts with search bar. when i search for particular account, the below code is not working.
what should i add to filter records from list of records which i got. please help me out from this issue.
Thank you :)
Component:
Controller
Apex class:
From this below code i am getting list of accounts with search bar. when i search for particular account, the below code is not working.
what should i add to filter records from list of records which i got. please help me out from this issue.
Thank you :)
Component:
<aura:component controller="AccountRecord"> <aura:handler name="init" value="{!this}" action="{!c.doInit}"/> <aura:attribute name="namevalue" type="string"/> <aura:attribute name="Account" type="Account"/> <lightning:input label='' value="{!v.namevalue}" /> <br></br> <div><lightning:button label="Search" onclick="{!c.handleClick}"/><br/></div> <!-- <lightning:button variant="destructive" label="search" onclick="{! c.handleClick }"/> --> <table class="slds-table slds-table_cell-buffer slds-table_bordered "> <thead> <tr class="slds-line-height_reset"> <th scope="col"> <div class="slds-truncate">ACCOUNT ID</div> </th> <th scope="col"> <div class="slds-truncate">ACCOUNT NAME</div> </th> <th scope="col"> <div class="slds-truncate">STATUS</div> </th> </tr> </thead> <aura:iteration items="{!v.Account}" var="account"> <tbody> <tr class="slds-hint-parent"> <td scope="row" data-label="Account Id"> <div class="slds-truncate"> {!account.Id}</div> </td> <td scope="row" data-label="Account Name"> <div class="slds-truncate"> {!account.Name}</div> </td> <td scope="row" data-label="Account Status"> <div class="slds-truncate"> {!account.Status__c}</div> </td> </tr> </tbody> </aura:iteration> </table> </aura:component>
Controller
({ handleClick : function(component, event, helper) { var acc1=component.get("v.namevalue"); var action = component.get("c.accountInfo"); action.setParams({ acc: acc1 }); action.setCallback(this, function(response){ var similarProperties = response.getReturnValue(); component.set("v.Account", similarProperties); }); $A.enqueueAction(action); }, doInit: function(component, event, helper){ var action = component.get("c.accountInfo1"); action.setCallback(this, function(response){ debugger; var similarProperties1 = response.getReturnValue(); console.log(similarProperties1); //var myJSON = JSON.stringify(similarProperties1); //alert(myJSON); component.set("v.Account", similarProperties1); }); $A.enqueueAction(action); } })
Apex class:
public class AccountRecord { @AuraEnabled public static String accountInfo(String acc){ Account ac=[select id,name,status__c from account where name=:acc limit 1]; String acc1=ac.id+' '+ac.name+' '+ac.status__c; return acc1; } @AuraEnabled public static List<Account> accountInfo1(){ list <Account> Ac1=[select id,name,status__c from account]; return Ac1; } }
Please refer below code:
All Answers
The logic is fine and when you will put console log, you will find the Account record with the namevalue you are searching for.
The issue is with the component - UI which is not getting re-rendered when you are trying to search with the namevalue.
Please refer below code:
Main problem here is with return type of 'accountInfo' method. In your lightning component, you are displaying account records using 'Account' attribute which is type of Account i.e. it can be object or list<object>.
So in your first case i.e. in case of doinit you are returing List<Account> from method 'accountInfo1' so it is working fine.
But in other case where you are searching for particular account, 'accountInfo' method is called which has return type as 'String' thats why lightning component is not able to find any value for {!account.Id}, {!account.Name} and {!account.Status__c}.
To fix this you have to update return type of 'accountInfo' method i.e. your 'AccountRecord' class will look like this :
Please mark this as answer if it works for you.
Thanks
IF( ISPICKVAL( Status__c , "Active") , value_if_true, value_if_false)
You need to use:
IF( AND(ISPICKVAL( Status__c , "Active"), ISCHANGED(Status__c)) , value_if_true, value_if_false)