I have two customfields, checkbox and Lookup fields, my requirement is if i check that checkbox then only lookup field is displayed otherwise not displayed.

  • 1
    you can rendered attribute to the lookup field and share your code here so you will get a batter solution based on your code
    – HSdev
    Apr 13, 2017 at 8:22

2 Answers 2


What is needed: When CheckBox is checked, then only lookup field should be visible on page layout.


  • Create a Record Type1 and associate the cloned copy of the page layout that you are using for your object and make sure you add Lookup field in this layout.
  • Create a workflow that is fired whenever Checkbox field is checked (workflow 3rd criteria, when subsequently meets the criteria)and create a field update to update the record type1 to the one you just created.

If you want to have this feature that on uncheck that field shouldn't be visible back again, then same way to create a record type2 and associate your original page layout with it. And then create a workflow that works when checkbox is unchecked to update to record type2. Don't forget to keep Record Type 2 as default.

Let me know if you need help!!

  • Thanks for your response. could you please explain me the 2nd point as i am not getting it. Apr 13, 2017 at 11:27
  • What I meant was on check of the checkbox, the workflow will work and lookup field is displayed on page. If in case we need, that again on uncheck of checkbox, lookup field gets hidden from the page layout then we can do the 2nd mentioned solution that is, Creating another recordtype and associating the layout without the lookup field with it and then creating the workflow that works on uncheck of checkbox and updates to this record type that has without lookup layout associated. Apr 13, 2017 at 12:06
  • Thank you for the clarification. But unfortunately its not worked the way you described. The lookup field is displayed only after record get saved,not on check of the checkbox. Apr 13, 2017 at 12:27
  • True, only after save this is supposed to work, what I have mentioned. Only in VisualForce page, one can control the dynamic rendering of data/fields, but not in the standard SF page. Apr 13, 2017 at 12:47

I'm sharing one example for you, since you have not shared any code base:

VF Page

<apex:page standardController="contact" extensions="zz_CBExtension">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockSection >
                <apex:pageBlockSectionItem >
                    <apex:outputLabel >Temp CB</apex:outputLabel>
                    <apex:inputCheckbox id="tempCB" onchange="renderLKP(this.checked);" selected="{!myCBInput}"/>
                <apex:pageBlockSectionItem >
                    <apex:outputLabel >Lookup Field</apex:outputLabel>
                    <apex:outputPanel id="tempLKP">
                        <apex:inputField value="{!contact.accountId}" rendered="{!myCBInput}"/>
        <apex:actionFunction name="renderLKP" reRender="tempLKP">
            <apex:param name="tempParam" value="" assignTo="{!myCBInput}"/>


public class zz_CBExtension {
    public boolean myCBInput{get; set;}
    public zz_CBExtension(ApexPages.StandardController controller) {



You must log in to answer this question.

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