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
Janno RipJanno Rip 

Set <apex:inputCheckBox> to default True and pass that value to controller

Hello developers,

I have the following checkbox on my visualforce page:
<apex:inputCheckBox id="filter1" value="{!fcb}">
        <apex:actionSupport event="onclick" action="{!findNearby}" rerender="geomap"/>
        </apex:inputCheckBox>
        <apex:outputLabel for="filter1" value="nur aus verwandter Branche ({!currentAccount.WZ_Abteilung__c})" />

So there is no actual field on the account, it just "exists" on the visualforce page.

I am passing the value to my class who runs different queries depending whether this checkbox is true or false:
 

// FILTER 1 (Branche)
     public boolean fcb { get; set; }
     // FILTER 2 (Owner)
     public boolean fco { get; set; }
     // FILTER 3 (perfect fit)
     public boolean fcf { get; set; }
        
     public FindNearbyController (boolean fcb, boolean fco, boolean fcf) {
     this.fcb = fcb;
     this.fco = fco;
     this.fcf = fcf;
     }
...
if (fcb == true && fco == false)  {
       
       warehouses =  [
                               SELECT Id, Name,URL_zum_CC__c,Mitarbeiternzahl_final__c,Auftragseingangstyp__c,AD_MS_Rel_Anzahl_bez__c,Vollst_ndiger_Name__c,ShippingStreet,LocateCity__longitude__s, LocateCity__latitude__s, OwnerId,GeoLocPosition__c,Accountinhaber_Text__c,WirtschaftszweigWZ08__c,WZ_Code_ebene_2__c,AE_letzte_12_Monate__c,anzeigendaten_de_ID_account__c,indexurl__c
                               FROM Account 
                               WHERE Letzte_gew_Opp_OneSales_in_Tagen__c <= :decimal.valueof(myTime) AND DISTANCE(LocateCity__c, GEOLOCATION(:dlat,:dlon), 'km') < :decimal.valueof(myInput) AND Id != :theaccId AND WZ_Code_ebene_2__c= :currentAccount.WZ_Code_ebene_2__c
                               ORDER BY DISTANCE(LocateCity__c, GEOLOCATION(:dlat,:dlon), 'km')  
                               LIMIT :recordLimit
                      ];

What I am trying to achieve is to set {!fcb} by default to true, so that the 1st query runs with pageload. I already tried "selected = 'true'". While the checkbox gets actually checked, the query does not get fired. Only when I "re-trigger" my "action" it will query. 

I would conclude that 'selecetd = true' is only for "visual" and there is no actual value getting passed to the controller?! Or is event="onclick" the problem?

How can I make this work? That the query runs on pageload with {!fcb} set to true.

Thanks in Advance!

 

ANUTEJANUTEJ (Salesforce Developers) 
Hi Janno,

This is just an idea why not initially query with the value set to true and after which you can try executing the query with in the function with the value of the parameter that is set in the ui.

In case if the above helps in your implementation can you please mark this as the best answer so that it can be used by others in the future.

Regards,
Anutej
Janno RipJanno Rip
Hello Anutej,


but how exactly do I set the value to true inside the query? 

Greetings