+ Start a Discussion
ludiludi 

Apex Auto Check Check box

Hi,

New with salesforce code:

I am having issues with getting a custom visual page to auto check a check box. I feel like this is happening because it is a custom page, and something needs to be added into the apex code to force a true value into the checkbox(I am not sure where) to do this. Here is what my apex code for this value looks like for the checkbox on this apex custom visual page:(Any help is much apprecciated thanks!)

        <apex:inputField value="{!Account_Request__c.Test_route__c}" required="false"/>
Best Answer chosen by Admin (Salesforce Developers) 
sai.sfsai.sf

<apex:page standardcontroller="Account_Request__c">
 <apex:form >
 <apex:pageblock >
 <apex:pageblockSection >
  <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Allow Route to US"  />
                    <apex:inputCheckbox value="{!Account_Request__c.Allow_Route_to_US__c}"  selected="true" />
   </apex:pageBlockSectionItem>
  </apex:pageblockSection>
  </apex:pageblock>
 </apex:form>
</apex:page>

All Answers

sai.sfsai.sf

go to the checkbox field and make it  default value as checked.

ludiludi

Hi Sai,

 

Thanks for the response; however, I wish it was this easy =[. We have already set the default value to checked, but when going to that custom page and loading the checkbox it is not checked. We think it has something to do with it being a custom page, or something that may need to be changed in the apex page.

sai.sfsai.sf

 for me its working..i don't  know it looks like u may be using apex:inputcheckbox..try using apex:inputfield

sai.sfsai.sf

<apex:page standardcontroller="opportunity">
 <apex:form >
  <apex:inputfield value="{!opportunity.Review__c}"/>
 </apex:form>
</apex:page>

sai.sfsai.sf

try removing required=false from the tag

ludiludi

I tried that...that didnt work, but here is my work around that works: However, the font doesnt match up and this is an issue, when i use the selected it doesnt show the value text with the check box, only the checked box, and then aligning is way off.

 

    <apex:outputPanel >Allow Route to US
                            <apex:inputCheckbox value="{!Account_Request__c.Allow_Route_to_US__c}" selected="true" />
                              </apex:outputPanel>
sai.sfsai.sf

<apex:page standardcontroller="Account_Request__c">
 <apex:form >
 <apex:pageblock >
 <apex:pageblockSection >
  <apex:pageBlockSectionItem >
                    <apex:outputLabel value="Allow Route to US"  />
                    <apex:inputCheckbox value="{!Account_Request__c.Allow_Route_to_US__c}"  selected="true" />
   </apex:pageBlockSectionItem>
  </apex:pageblockSection>
  </apex:pageblock>
 </apex:form>
</apex:page>

This was selected as the best answer
ludiludi

Awesome up and working, thanks Sai :D