0

My Apex Controller

public class wrapperDisplayController {


 public static List<wrapperAccountCheckBox> LstWrp;
 public static List<wrapperAccountCheckBox> LstWrp_Selected;
 public wrapperDisplayController()
{
    LstWrp=new List<wrapperAccountCheckBox>();
    LstWrp_Selected=new lIst<wrapperAccountCheckBox>();
    List<Account> accLst=new List<Account>([Select Id, Name,Industry, (Select Id,LastName from Contacts) ,Website from Account ]);
    for(integer i=0;i<accLst.size();i++)
    {
    boolean check=true;
    if(accLst[i].Industry== null)
    {
        check=false;
    }
        LstWrp.add(new wrapperAccountCheckBox(check,String.ValueOf((i+1)),accLst[i]));
    }
}


// wrapper or Inner class with @AuraEnabled {get;set;} properties*    
public class wrapperAccountCheckBox
{
   @AuraEnabled  public boolean checkbox{get;set;}
   @AuraEnabled  public String SLNo{get;set;}
   @AuraEnabled  public Account acc{get;set;}

     public wrapperAccountCheckBox()
    {

    }
    public wrapperAccountCheckBox(boolean c,String s,Account a)
    {
        this.checkbox=c;
        this.SLNo=s;
        this.acc=a;
    }
    public wrapperAccountCheckBox(String s,Account a)
    {
        this.SLNo=s;
        this.acc=a;
        checkbox=true;
    }
    public boolean equals(Object o){
        return (acc.Name == ((wrapperAccountCheckBox) o).acc.Name);
    }
}
@AuraEnabled
public static List<wrapperAccountCheckBox> getAccount(){

    LstWrp=new List<wrapperAccountCheckBox>();
  //   List<wrapperAccountCheckBox> LstWrp_Selected=new 
    lIst<wrapperAccountCheckBox>();
    List<Account> accLst=new List<Account>([Select Id, Name,Type,Phone,Fax,Industry, (Select Id,LastName from Contacts) ,Website from Account]);
    for(integer i=0;i<accLst.size();i++)
    {
    boolean check=false;

        LstWrp.add(new wrapperAccountCheckBox(check,String.ValueOf((i+1)),accLst[i]));
    }
    return LstWrp;
}
   @AuraEnabled      
  public  static List<wrapperAccountCheckBox> RedirectSelectedAcc()
{
       LstWrp_Selected=new List<wrapperAccountCheckBox>();
          for(wrapperAccountCheckBox wrp:LstWrp)
    {
        if(wrp.checkbox==true)
        {
            if(LstWrp_Selected.indexOf(wrp) == -1){
                LstWrp_Selected.add(wrp);
            }
        }
    }
    return LstWrp_Selected;
}
  @AuraEnabled            
 public static List<wrapperAccountCheckBox> searchAccount(String account){
    String searchstr = ('%' + account + '%');
    List<Account> accLst = [SELECT Name, Id, Industry FROM Account WHERE Name LIKE: searchstr];
                 for(integer i=0;i<accLst.size();i++)
    {
        boolean check=false;
        LstWrp.add(new wrapperAccountCheckBox(check,String.ValueOf((i+1)),accLst[i]));
    }
    return LstWrp;

} }

My Lightning component

<aura:attribute name="searchValue" type="String" />


  <aura:attribute name="isModalOpen" type="boolean" default="false"/>

<aura:attribute name="myBool" type="Boolean" default="false"/>
<!--   <aura:method name="updateAcc" action="{! c.doInit}" description="method for rendered list after add new account "/>-->

<ui:inputCheckbox aura:id="checkbox" name="check" label="View Table?" value="{!v.myBool}" />
<aura:attribute name="newAccount" type="Account" default="{'Name':'',
                                                          'Industry':'',
                                                          'Description':'',

                                                          'sobjectType':'Account'}"/>
    <aura:handler event="c:applicationEvent" action="{!c.doInit}" />
-->
<aura:if isTrue="{!v.myBool}">

    <div class="slds-grid">
<div class="slds-col slds-align-bottom" style="margin-top:10px">
     <c:SearchBarCmp />
</div>

    <table class="slds-table slds-table_bordered slds-table_cell-buffer" >
        <thead>
            <tr class="slds-text-title_caps">

                <td>
                    <b>Name</b>
                </td>
                <td>
                    <b>Account</b>
                </td>
                <td>
                    <b>Industry</b>
                </td>
                <td>
                    <b>Contacts</b>
                </td>
            </tr></thead>
        <aura:iteration items="{!v.LstWrp}" var="accs1" >
            <tr>  
                <td>
                    <ui:inputCheckbox aura:id="checkbox" name="check"  value="{!accs1.checkbox}" /></td>
                <td> {!accs1.acc.Name}  </td>
                <td> {!accs1.acc.Industry}  </td>
                <!--   <td>   {!accs1.Contacts.lastName}  </td> -->
                <table>
                    <aura:iteration items="{!accs1.acc.Contacts}" var="con1" >
                        <tr>
                            <td>{!con1.LastName}</td>
                        </tr>
                    </aura:iteration>
                </table>
            </tr> 
        </aura:iteration>                                           
    </table>
    </div>
</aura:if>
<div class="slds-m-around_xx-large">
    <lightning:button variant="brand"
                      label="Edit Account?"
                      title="What is Modal/PopUp Box?"
                      onclick="{! c.openModel }" /></div>
<aura:if isTrue="{!v.isModalOpen}" >
EDIT PAGE Account Name Industry
</aura:if>

my Controller js

({ doInit : function(component, event, helper) {

var action = component.get("c.getAccount");


    action.setCallback(this,function(response){
                       var state= response.getState();
    $A.log(response);
    if(state==="SUCCESS")
    {
        component.set("v.LstWrp",response.getReturnValue());
    }
                       });
$A.enqueueAction(action);

},


openModel: function(component, event, helper) {
  // Set isModalOpen attribute to true
   var action=component.get("c.RedirectSelectedAcc");
    /*var p=event.getParams('arguments');
    if(p){
        var accounts=p.accounts;
    }*/
    action.setCallback(this,function(response){
                       var state= response.getState();
    $A.log(response);
    if(state==="SUCCESS")
    {
        var d = response.getReturnValue();
        component.set("v.LstWrp_Selected",response.getReturnValue());
    }
                       });
$A.enqueueAction(action);
  component.set("v.isModalOpen", true);

},

   closeModel: function(component, event, helper) {
  // Set isModalOpen attribute to false  
  component.set("v.isModalOpen", false);

},

submitDetails: function(component, event, helper) {
  // Set isModalOpen attribute to false
  //Add your code to call apex method or do some processing
  component.set("v.isModalOpen", false);

},

 changeCheckBox : function(component, event, helper) {
var getAttributeValue = component.get("v.myBool");
if(getAttributeValue==true){
    component.set("v.myBool", true);
}
else{
    component.set("v.myBool", false);
}

}, search : function(component,event) {

    var action=component.get("c.searchAccount");

    action.setParams({

        "account" : component.get("v.searchValue")

    });

    action.setCallback(this,function(response){

        var state=response.getState();

        console.log("State=== "+state);

        if(state=="SUCCESS")

        {

            var resp=response.getReturnValue();

            console.log("resp ==="+JSON.stringify(resp));

            component.set("v.LstWrp",resp); 

        }

         else {

            console.log("Failed with state: " + state);

        }

                       });

    $A.enqueueAction(action);

} })

  • Welcome to SFSE! Please take the tour and read How to Ask. You've provided a lot of code here, but you haven't really provided a description of what the problem is. That makes it hard for other people to try to help you. If you're getting an error message, it's always a good idea to include the full text of the error verbatim (that is, word-for-word, no paraphrasing). A detailed description goes a long way in narrowing down the potential problems. You should add additional details to your question by making an edit. – Derek F Feb 7 at 12:45

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.