3

I have a visualforce page with standard controller 'contact' and an extension class. This visualforce page appears in a section on each Contacts record page. The page renders several SObject checkboxes.

The issue is when a user clicks the checkbox, the selection is not remembered when the Contacts record page and therefore the VF page section are reloaded. How do I code the VF page so that when the Contact record is opened again, the checkboxes that were checked remain checked?

Please help.

Here is my VF page:

Currently, I have not written any code in extension class or the check_selection method:

<apex:page standardController="Contact" extensions="VFforEmailTemplateController" tabStyle="Contact">
<apex:form >
 <apex:pageBlock id="theBlock">    
      <apex:pageBlockTable value="{!contact}" var="c">
            <apex:column headerValue="On Approved List">
                 <apex:inputField value="{!c.EJF_On_Approved__c}"> 
                      <apex:actionSupport event="onclick" reRender="theBlock" action="{!check_selection}"/> 
                   </apex:inputfield>   
               </apex:column>
6
  • To remember your selection after the checkbox selection event the values must be stored in sfdc object .Be precise with your question so that we can help.A code snippet of code will be great to understand the issue? Jun 27, 2013 at 3:36
  • Sure, here is my VF page code. No code in extension class/check_selection method: <apex:page standardController="Contact" extensions="VFforEmailTemplateController" tabStyle="Contact"> <apex:form > <apex:pageBlock id="theBlock"> <apex:pageBlockTable value="{!contact}" var="c"> <apex:column headerValue="On Approved List"> <apex:inputField value="{!c.EJF_On_Approved__c}"> <apex:actionSupport event="onclick" reRender="theBlock" action="{!check_selection}"/> </apex:inputfield> </apex:column>
    – Rosh
    Jun 27, 2013 at 4:17
  • Are you including this VF page from the pagelayout of contact record? You want it to save the selection on save of the contact record? In which object are you storing these checkbox values? in contact?
    – Prady
    Jun 27, 2013 at 7:11
  • Appreciate your response. Yes, this VF page appears on the page layout of a contact record. I want the checkbox to remain checked when I navigate back to the contact record after having selected the checkbox. I do not have a save button. Its just a checkbox on a VF page in a Contact record. Once a checkbox is selected, this selection should be remembered when you navigate back to the same contact record. This checkbox is a custom Contact object field (checkbox) and I'm looking to save the value in this field (EJF_On_Approved). Thanks for your time.
    – Rosh
    Jun 27, 2013 at 7:22
  • Why do you want to have it in a VF page? Why dont you show that checkbox in the contacts pagelayout itself?
    – Prady
    Jun 27, 2013 at 11:27

2 Answers 2

3

Try to use an extension with a ApexPages.StandardController. After clicking on the checkbox just save the record so your selection will not disappear:

Visualforce:

<apex:page standardController="Contact" extensions="VFforEmailTemplateController" tabStyle="Contact">

    <apex:form>
        <apex:pageBlock id="theBlock">
            <apex:pageBlockSection columns="2">
                <apex:inputField value="{!Contact.EJF_On_Approved__c}"> 
                    <apex:actionSupport event="onclick" reRender="theBlock" action="{!saveRecord}"/> 
                </apex:inputField>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>

</apex:page>

Extension:

public with sharing class VFforEmailTemplateController{

    public Contact cont { get; set; }
    public ApexPages.StandardController c;

    // Here defining the Contact record and the standard controller
    public VFforEmailTemplateController(ApexPages.StandardController controller){
        this.cont = (Contact)controller.getRecord();
        c = controller;

    }

    // Saving the current record
    public PageReference saveRecord(){
        try{
            c.save();
        }
        catch(Exception e){
        }
        return null;
    }
}
7
  • It worked great, thanks a lot for your solution. Sincerely appreciated. I'd vote up but I'm told I need a rep of 15. Anyway, can you please tell me how I can use system.debug() to see what's happening? Just what needs to go in the parenthesis. Also, could you please suggest some tutorials to learn things like 'this.cont' - I don't even know what that means and where to start. Began working on SF two days ago. Many thanks for your effort.
    – Rosh
    Jun 27, 2013 at 8:59
  • 1
    You can first accept this solution so you will get more reputation and then upvote it if you wish so :) Lern more about controller e xtenstions here: salesforce.com/us/developer/docs/pages/Content/… And here about system methods: salesforce.com/us/developer/docs/apexcode/Content/… Generally use salesforce online docs, it is very very helpfull. Jun 27, 2013 at 9:11
  • Accepted, still 2 points shy for a vote up privilege. Thanks again.
    – Rosh
    Jun 27, 2013 at 9:25
  • Here you can learn more about stackexchange reputation: salesforce.stackexchange.com/help/whats-reputation Jun 27, 2013 at 9:32
  • Mast0r, I need your help again. This code works fine for one checkbox selection. Now when I have two checkboxes, they behave funny. I replicated the first checkbox code for the second, using the same saveRecord method.
    – Rosh
    Jun 27, 2013 at 9:41
1

Instead of the whole controller extension and the apex class, I can simply use the standard method {!quickSave}. The other standard method {!save} doesn't work because the entire contact page gets loaded into the inline VF component section that is meant to hold my custom grid/table.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .