+ Start a Discussion
D VelD Vel 

Unable to get the new field value from the VF Page

I have input Checkboxes in the VF page on the Lead record with the requirement that if one of the field is checked the other should be checked as well when the save button is clicked on the VF Page and it is the same when being unchecked
User-added imageThere is this 3rd field on the Lead record which dont exists on the VF Page but needs to updated depending on the above two fields
User-added imagebelow is what I tried
VF Page
<apex:pageblockSectionItem >
                        <apex:outputPanel >
                            <div class="ListLevel01">
                                <apex:outputLabel value="Type 1"></apex:outputLabel>
                            </div> 
                        </apex:outputPanel>
                        <apex:inputcheckbox value="{!leadRec.Type_I_AI__c}" styleClass="ListLevel01">
                            <apex:actionSupport event="onchange" reRender="form" status="status"/>
                        </apex:inputcheckbox>
                    </apex:pageblockSectionItem>
                    <apex:pageblockSectionItem >
                        <apex:outputPanel >
                            <div class="ListLevel01">
                                <apex:outputLabel value="Type 1"></apex:outputLabel>
                            </div> 
                        </apex:outputPanel>
                        <apex:inputcheckbox value="{!leadRec.Type_I_DOM__c}" styleClass="ListLevel01">
                            <apex:actionSupport event="onchange" reRender="form" status="status"/>
                        </apex:inputcheckbox>
                    </apex:pageblockSectionItem>

             ..................
  </apex:pageblock>    
  <apex:commandButton value="Save" style="margin-left:900px;" action="{!finalUpdates}" rerender="form"  oncomplete="RefreshPrimaryTab('{!Lead.id}'); return true;" />
 </apex:form>
The finalUpdates updates the Lead record which in turn fires the trigger like below
set<Id> leadIds = new set<Id>();
    for(Lead l : Trigger.new){
        leadIds.add(l.Id);
    }
    if(!leadIds.isempty() && checkRecursiveTrigger.ranOnce == false)
       LeadTriggerHandler.updateAOI(trigger.newMap, trigger.oldMap);
}
Apex Class
Public class LeadTriggerHandler{
 public static void updateAOI(Map<Id, Lead> newLeads, Map<Id, Lead> oldLeads){
    Set<Id> resultIds = (new Map<Id,Lead>(newLeads)).keySet();
           List<Lead> Leadlist = [Select Id, Type_I__c,Type_I_AI__c,Type_I_DOM__c
                               from Lead WHERE Id IN: resultIds];
        List<Lead> updateList = new List<Lead>();
        set<id> LeadIds= new set<Id>();
        for(Lead l : Leadlist){
                     if(   newLeads.get(l.Id).Type_I_DOM__c == true || newLeads.get(l.Id).Type_I_AI__c  == true)
            {
                l.Type_I_DOM__c = true;
                l.Type_I_AI__c  = true;
                l.Type_I__c = true;
                if(!leadIds.contains(l.Id)){
                    leadIds.add(l.Id);
                    updateList.add(l);
                }                
            }
            
            if(newLeads.get(l.Id).Type_I_DOM__c == false || newLeads.get(l.Id).Type_I_AI__c  == false)
            {
               l.Type_I_DOM__c = false;
                l.Type_I_AI__c  = false;
                l.Type_I__c = false;
                if(!leadIds.contains(l.Id)){
                    leadIds.add(l.Id);
                    updateList.add(l);
                }                
            }
         .............
But this doesnt work as expected, it executes both the if condition if condition if I just click on just one field and not even touch the other field in the end even if 1 field is selected I see false on all the three fields. I now understand my approach here is wrong but not sure how to handle it. Any help is greatly appreciated
shaik murthujavalishaik murthujavali
Hi,
Try using below code.

<script type="text/javascript">
        function selectAllCheckboxes(obj,receivedInputID){
            var inputCheckBox = document.getElementsByTagName("input");                 
            for(var i=0; i<inputCheckBox.length; i++){         
                if(inputCheckBox[i].id.indexOf(receivedInputID)!=-1){                                    
                    inputCheckBox[i].checked = obj.checked;
                }
            }
        }
    </script>
===============
<apex:inputCheckbox id="inputId" onclick="selectAllCheckboxes(this,'inputId')"/>


If it works for you pls mark as a best answer, it helps other too.
Thanks
D VelD Vel
I am sorry I am not following. When I uncheck the checkbox it needs to be updating the other place where the field appears.