0

I have a custom object

MyObject__c

I've added a custom field which is of type check box.

one__c

If a system admin ticks this checkbox on the object in the Salesforce UI, I want an apex element to appear in my Visualforce page, by way of the render attribute

<apex:page standardController="MyController">
         <apex:outputLink target="_top" value="page.html" rendered="{!one}">Click here</apex:outputLink>
</apex:page>

Here is a stripped down version of my controller:

public with sharing class MyController {

    public Boolean one {get; set;}

    public MyController() {

        String query = 'SELECT id, one__c FROM myObject__c WHERE ID = :myObjectId LIMIT 1';

        myObject__c obj = database.query(query);

        one = obj.one__c;       
    }
}

Atm, one__c is always returning false, whether or not the box is ticked in the UI. I'm unsure as to the logic I need to add to my controller to 'catch' the state of the check box.

Could anyone help?

2

There doesn't seem to be an issue with your controller. You need to add a mechanism in your VF page to actually rerender a portion of your page when the checkbox is changed. I would use an ActionRegion and ActionSupport to accomplish this.

<apex:outputLink target="_top" value="page.html" rendered="{!one}" id="myLink">Click here</apex:outputLink>

<apex:actionRegion>
     <apex:inputCheckBox value="{!one}" id="myCheckBox">
          <apex:actionSupport event="onchange" rerender="myLink"/>
     </apex:inputCheckBox>
</apex:actionRegion>

This now is now telling your page to rerender your outputlink when the value of the checkbox is changed.

Take a look at the documentation of the ActionRegion tag for a little more info.

https://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_actionRegion.htm

2
  • Thanks for the reply, but the check box is on the object in an admin page. If a System Admin checks the box, a Standard User will then be able to see the above element. The check box isn't actually accessible on my page.
    – Daft
    Aug 27 '14 at 21:18
  • 1
    Ok, I would add those details to the question so its a bit more clear. Aug 27 '14 at 23:58
0

So that leaves myObjectId as loose end. Are you sure that the admin and the user dealing with the same record?

But we can't answer it because we neither see what happens on the admin page nor how myObjectId is initialized.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.