samedi 21 mai 2022

checkbox value set as false when tried to update other page

I have a data in a table that has 3 pages. where in the data table there is a checkbox to update data fields that have a value of true or false, however, when I make changes to the data on page 2, the checkboxes on page 1 and 3 will always be false. so, all my data in page 1 and 3 will set as false.

i tried to change it without checkbox and it works perfectly, as if there is something wrong with the checkbox, could u guys tell me where is my fault and what should i do?? i really need ur help guys, thankyou

this is my code now

<apex:tabPanel switchType="client" selectedTab="name2" id="theTabPanel">
                <apex:tab label="Validate" name="validate" id="tabValidate">
                    <apex:outputPanel id="wrapSalesPlanTable">
                        <script>
                        j$(document).ready( function () {
                            j$('[id$="salesPlanTable"]').DataTable({iDisplayLength: 50, searching: false, dom: 'lBfrtip', stateSave: true, order: [], buttons: ['excel']});
                        });
                        </script>
                        <table id="salesPlanTable" class="stripe row-border order-column" style="width:100%"> 
                            <thead>
                                <tr>
                                    <th id="columnA">No</th>
                                    <th id="columnA">PPD Delivery Schedule</th>
                                    <th id="columnB">Check Opex</th>
                                </tr>
                            </thead>
                            <tbody>
                                <apex:repeat value="{!dataSalesPlan}" var="i">
                                    <tr>
                                        <th id="columnA">
                                            <apex:outputText value="{!i.index}"/>
                                        </th>
                                        <th id="columnA">
                                            <apex:input type="date" style="width:100px" id="deliveryschedule" value="{!i.deliverySchedulePPD}"/>
                                        </th>
                                        <th id="columnB">
                                            <apex:inputCheckbox styleClass="checkOpex{!i.spd.ID} checkOpex {!i.spd.ID}" value="{!i.opex}"/>
                                        </th>
                                     </tr>
                                </apex:repeat>
                            </tbody>
                        </table>
                    </apex:outputPanel>
                </apex:tab>
</apex:tabPanel>

Apex code

public void loadData() {
       getDataSalesPlan = Database.query(query);
        Integer spdIndex = 0;
        dataSalesPlan = new List<SPDWrapper>();
        for(Sales_Plan_Detail__c spd : getDataSalesPlan) {
            dataSalesPlan.add(new SPDWrapper(spdIndex, spd, getMaterialGroup(spd.Material__r.Material_Group__c), getAreaSOD(spd.Plant__c)));
            spdIndex++;
        }
}
public void save() {
        Integer spdIndex = 0;
        Boolean setIDSPD;
    for(Sales_Plan_Detail__c ppd: getDataSalesPlan){
           setIDSPD = FALSE;
           SPDWrapper spdWrapper = dataSalesPlan[spdIndex];
           
           if(ppd.Checklist_Opex__c != spdWrapper.opex){
               updateOpexList.put(spdWrapper.spd.Id, spdWrapper.opex);
               setIDSPD = TRUE; 
           }
           
           if(setIDSPD == TRUE){
               updateSPDIds.add(spdWrapper.spd.Id);
           }
           spdIndex++;
           
        }
        Set<String> SPDValue = new Set<String>(updateSPDIds);
        SPDValue.addAll(updateSPDIds); 
     
        List<Sales_Plan_Detail__c> spdToUpdate = new List<Sales_Plan_Detail__c>();
        if(SPDValue.size() > 0){    
            for(Sales_Plan_Detail__c ent : [SELECT Id, Prospect__r.Id FROM Sales_Plan_Detail__c WHERE Id IN :SPDValue]){
                Sales_Plan_Detail__c spdList = new Sales_Plan_Detail__c();
                spdList.Id = ent.Id;
                if(updateOpexList.containsKey(ent.Id)) {
                    spdList.Checklist_Opex__c = updateOpexList.get(ent.Id);
                }
                spdToUpdate.add(spdList);
            }
        Database.SaveResult[] spdResults = Database.update(spdToUpdate, false);
}

public class SPDWrapper{
        public Integer index {get; set;}
        public Sales_Plan_Detail__c spd {get;set;}
        public Boolean opex {get; set;}
        public SPDWrapper(Integer getIndex, Sales_Plan_Detail__c getSpd, String materialGroupBucket, String getAreaSOD){
            index = getIndex;
            spd = getSpd;
            opex = spd.Checklist_Opex__c;
         }
}



Aucun commentaire:

Enregistrer un commentaire