function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sree SalesforceSree Salesforce 

Lightning Wrapper Class Issue.

Component:-
<aura:component controller="searchAccountController">
   <ltng:require styles="{! $Resource.SLDS24+ '/assets/styles/salesforce-lightning-design-system.css'}"/>
    <aura:attribute name="wrappers" type="wrapperaccount"> </aura:attribute>
    <aura:attribute name="accounts" type="Account" />
    <aura:attribute name="searchResult" type="List" description="use for store and display account list return from server"/>
   <aura:attribute name="searchKeyword" description="use for input" type="string" ></aura:attribute>
    <aura:attribute name="Message" type="boolean" default="false" description="use for display no record found message"/>
    <div class="slds-m-around--large">
       <form class="slds-form--inline"> 
         <div class="slds-form-element"> 
            <label class="slds-form-element__label" for="Search">Account Search</label>  
              <div class="slds-form-element__control" >
                <ui:inputtext aura:id="searchId" value="{!v.searchKeyword}" placeholder="Type Account Name"  class="slds-input"></ui:inputtext>
              </div>
            </div> 
             <div class="slds-form-element">
                 <button type="Button" onclick="{!c.SearchJS}" class="slds-button slds-button--brand">Search</button>
                 </div>
        </form>   
         <table class="slds-table slds-table--bordered slds-table--cell-buffer">
            <thead>
                <tr class="slds-text-title--caps">
                    <th scope="col">
                         <div class="slds-truncate" title=" Name"> ID</div>
                    </th>
                    <th scope="col">
                         <div class="slds-truncate" title=" Name"> Name</div>
                    </th>   
                     <th scope="col">
                          <div class="slds-truncate" title="Type">Type</div>
                       </th>
                       <th scope="col">
                          <div class="slds-truncate" title="Industry">Industry</div>
                       </th>
                       <th scope="col">
                          <div class="slds-truncate" title="Phone">Phone</div>
                       </th>
                       <th scope="col">
                          <div class="slds-truncate" title="Fax">Fax</div>
                       </th>
                </tr>
            </thead>
            <tbody>
                 <aura:if isTrue="{!v.Message}">
               <div class="slds-text-color--error"> No Result Found...</div>
            </aura:if>
                <aura:iteration items="{!v.wrappers}" var="Wrap"> 
              <tr>
                  <td>
                     <div class="slds-truncate">{!Wrap.acc.Id}</div>
                  </td>
               <!--  <td>
                     <div class="slds-truncate">{!Wrap.acc.name}</div>
                  </td>
                  <td>
                     <div class="slds-truncate">{!Wrap.acc.Type}</div>
                  </td>
                  <td>
                     <div class="slds-truncate">{!Wrap.acc.industry}</div>
                  </td>
                    <td>
                     <div class="slds-truncate">{!Wrap.acc.Phone}</div>
                  </td>
                    <td>
                     <div class="slds-truncate">{!Wrap.acc.fax}</div>
                  </td> -->
              </tr>
                </aura:iteration>     
            </tbody>
        </table> 
      </div>     
     
</aura:component>
JS :-
({
    SearchJS : function(component, event, helper) {
        var searchKeyId=component.find("searchId"); 
        var searchKey=component.get('v.searchKeyword');
        alert('==searchKeyword'+searchKey);
        if(searchKey == '' || searchKey == null)
        {
            alert('--enter');
          //  searchKeyId.set("v.errors",[{message: "Enter search Keyword" }]);
             $A.util.addClass(searchKeyId,'errorClassAdd');
            //$A.util.removeClass(searchKeyId,'errorClassRemove');
        }
        else{
             $A.util.addClass(searchKeyId, 'errorClassRemove');
             $A.util.removeClass(searchKeyId, 'errorClassAdd');
            helper.searchHelper(component,event);
        } 
    },
})
Helper :- 
({
    searchHelper: function(component, event) {
        var action = component.get("c.searchmethod");
        alert('====key'+component.get("v.searchKeyword"));
        action.setParams({
            'searchKeyword': component.get("v.searchKeyword")         
        });
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                var storeResponse = response.getReturnValue();
                // if storeResponse size is 0 ,display no record found message on screen.
                if (storeResponse.length == 0) {
                    component.set("v.Message", true);
                } else {
                    component.set("v.Message", false);
                
                }
                var wrappers=new Array();
                for (var idx=0; idx<storeResponse.length; idx++) {
                   var wrapper = { 'acc' : storeResponse[idx],
                   'selected' : false
                            };
                    
               wrappers.push(wrapper);
                    alert('--wrapper--'+wrappers);
            } 
                 // component.set("v.searchResult", storeResponse);
                   component.set('v.wrappers', wrappers);
                    alert('==='+component.set("v.searchResult", storeResponse));
                
            } 
 
        });
        $A.enqueueAction(action);
 
    },
})

Apex:- 

public class searchAccountController {

 @AuraEnabled
  public static list<account> searchmethod(string searchKeyword)
  {
    system.debug('--enter --'+searchKeyword);
    String searchKey=searchKeyword + '%';
    system.debug('--enter =--'+searchKey);
    list<account> returnList =new list<account>();
    list<account> AccList=[select id,name,type,industry,phone,fax from account where name like: searchKey];
    for(account acc:AccList)
    {
    returnList.add(acc);
       }
    return returnList;
    
  }
    
    public class wrapperaccount{
       
        @AuraEnabled
        public Account acc {get; set;}
        @AuraEnabled
        public Boolean selected {get; set;}
    }
}

I have follwed this link  http://bobbuzzard.blogspot.in/2015/12/lightning-component-wrapper-classes.html

I am getting this error

User-added image
Priyankar PakhiraPPPriyankar PakhiraPP
Hi
Please can you create another apex class where you can just write the wrapper class (below) and remove this class from original controller class.
  public class wrapperaccount{
       
        @AuraEnabled
        public Account acc {get; set;}
        @AuraEnabled
        public Boolean selected {get; set;}
    }
}

Please check and let me know.

Happy Lightning learning