+ Start a Discussion
SF_MonkeySF_Monkey 

Checkbox not showing correct value

I have an apex method where I am comparing two list and updating a field which is a checkbox. On the table, the checbox is showing checked only the last added element to the list. I checked the log and it is working correctly according to it. Thanks! 

Apex method
List<Prospect__c> props = [select account__c, vertical__c from 
                            Prospect__c  where account__c = :accId order by name ];
        
        List<vertical__c> verts = [select name, id from vertical__c order by name];
        
        List<vertical__c> upper = new List<vertical__c>();
		         
        for(vertical__c m : verts){
           Set<String> s = new set<string>();
            s.add(m.Id);
            for(Prospect__c p :props){
                
                if(s.contains(p.Vertical__c)){
                    m.Included__c = true;
                    
                }
                else{
                    m.Included__c = false;
                    
                }
                
            }
            upper.add(m);
        }
        update upper;
        return upper;

 Lightning cmp:
<table class="slds-table slds-table--bordered slds-table--striped slds-table--cell-buffer " >
        <div aura:id="conEditForm" >
        <thead>          
            <tr class="slds-text-heading--small"> 
                <th scope="col"><span class="slds-truncate">Included</span></th>
                <th scope="col"><span class="slds-truncate">Name</span></th>
                <th scope="col"><span class="slds-truncate">Add</span></th>
                <th scope="col"><span class="slds-truncate">Remove</span></th> 
            </tr>
            
        </thead>
        <tbody >
            <aura:iteration items="{!v.data}" var="conList" >
                <tr>
                   
                    <th scope="row"><ui:outputCheckbox value="{!conList.Included__c}" aura:id="checker"/></th>
                    <td><a href="{!'/one/one.app?#/sObject/'+ conList.Id + '/view'}"><ui:outputText value="{!conList.Name}"/></a></td>                    
                    <td><button type="button" onclick="{!c.addVert}" class="slds-button slds-button--success slds-float_center"  id="{!conList.Id}">Add</button></td>                
                    <td><button type="button" onclick="{!c.delVert}" class="slds-button slds-button--destructive slds-float_center"  id="{!conList.Id}">Remove</button></td>
                    
                </tr>
            </aura:iteration>
        </tbody>
                 </div>
    </table>

 
Best Answer chosen by SF_Monkey
SF_MonkeySF_Monkey
I just had to add break clause to the loop.
for(vertical__c m : verts){
           Set<String> s = new set<string>();
            s.add(m.Id);
            for(Prospect__c p :props){
                
                if(s.contains(p.Vertical__c)){
                    m.Included__c = true;
                    break;
                }
                else{
                    m.Included__c = false;
                    
                }
                
            }
            upper.add(m);
        }