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
Becky Miller 15Becky Miller 15 

Need help with Default the Checkbox to Checked (VF and Apex Class)

I have a field on the OpportunityLineItem.To_Business_plan__c that I want when the product is selected it automatically defaults to checked on the Product Selector.  I have highlighted the piece of code not working.  Any help would be much appreciated.  

APEX CLASS:
public with sharing class opportunityProductEntryExtension {


    public Opportunity theOpp {get;set;}
    public Opportunitylineitem opli {get;set;}
    public String searchString {get;set;}
    public List<OpportunityLineItemWrapper> shoppingCart {get;set;}
    public List<PricebookEntry> availableProducts {get;set;}
    public Pricebook2 theBook {get;set;}

    public String toSelect {get; set;}
    public String toUnselect {get; set;}
    public Decimal Total {get;set;}

    public Boolean overLimit {get;set;}
    public Boolean multipleCurrencies {get; set;}

    
    public with sharing class controller {
    public list < opportunitylineitem> objb = [select to_business_plan__c from opportunitylineitem];
    public list <opportunitylineitem> getRecords() {
        if(objb <> null){
            for(opportunitylineitem  opli : objb){
                opli.to_business_plan__c = true;
            }
        }
        return objb;
    }
}

    
 
VisualForce:

                       <apex:column headerValue="{!$ObjectType.OpportunityLineItem.Fields.To_Business_Plan__c.Label}">
                                 <apex:inputCheckbox value="{!s.oli.To_Business_Plan__c}" id="objb"/>
                       </apex:column>

The page renders but the checkbox is not defaulting to checked.

 
BALAJI CHBALAJI CH
Hi Becky,

Please try below modified code:
public with sharing class opportunityProductEntryExtension {
    
    
    public Opportunity theOpp {get;set;}
    public Opportunitylineitem opli {get;set;}
    public String searchString {get;set;}
    //public List<OpportunityLineItemWrapper> shoppingCart {get;set;}
    public List<PricebookEntry> availableProducts {get;set;}
    public Pricebook2 theBook {get;set;}
    
    public String toSelect {get; set;}
    public String toUnselect {get; set;}
    public Decimal Total {get;set;}
    
    public Boolean overLimit {get;set;}
    public Boolean multipleCurrencies {get; set;}
    
    
    public with sharing class controller {
        public list < opportunitylineitem> objb = [select to_business_plan__c from opportunitylineitem];
        public list < opportunitylineitem> Updatedobjb = new list < opportunitylineitem> ();
        public list <opportunitylineitem> getRecords() {
            if(objb <> null){
                for(opportunitylineitem  opli : objb){
                    opli.to_business_plan__c = true;
                    Updatedobjb.add(opli);
                }
            }
            return Updatedobjb;
        }
    }
}

Let us know if that helps you.

Best  Regards,
BALAJI.
Becky Miller 15Becky Miller 15
Thank you.  The to_business_plan__c is still not updating when I hit Select on the product.  If I could send you all of the code perhaps that will help you --- help me?  I know I am so close.