+ Start a Discussion
kasa venkat 14kasa venkat 14 

Hi, 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,can we write any validationrule on this or any coding??

Hi, 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,can we write any validationrule on this or any coding??
Best Answer chosen by kasa venkat 14
Dileep KumarDileep Kumar

Hi Kasa,

I am writing code below to your Question.

public class ClassA{
    public cus1__c cus{get;set;}
    public ClassA(){
        cus = new cus1__c(); 
    }
    public void method(){
        if(cus.Check__c == true){
        insert cus;
        }
    }
}
 
<apex:page controller="ClassA">
<apex:form id="formId">
    <apex:inputField value="{!cus.Check__c}">
        <apex:actionSupport event="onclick"  reRender="formId"/>
    </apex:inputField>
    <apex:inputField value="{!cus.Account__c}" rendered="{!cus.Check__c==true}"/>
    <apex:commandButton value="Save" action="{!method}"/>
</apex:form>
  
</apex:page>


Please create one object and in that object you need to create one checkbox field and one lookup field.Now you can put above code in your class and page .click preview button on page you will see your solution.If it will work.Please mark it as a best answer.

If you will face any problem let me know.

Thanks,

Dileep

All Answers

Dileep KumarDileep Kumar

Hi Kasa,

I am writing code below to your Question.

public class ClassA{
    public cus1__c cus{get;set;}
    public ClassA(){
        cus = new cus1__c(); 
    }
    public void method(){
        if(cus.Check__c == true){
        insert cus;
        }
    }
}
 
<apex:page controller="ClassA">
<apex:form id="formId">
    <apex:inputField value="{!cus.Check__c}">
        <apex:actionSupport event="onclick"  reRender="formId"/>
    </apex:inputField>
    <apex:inputField value="{!cus.Account__c}" rendered="{!cus.Check__c==true}"/>
    <apex:commandButton value="Save" action="{!method}"/>
</apex:form>
  
</apex:page>


Please create one object and in that object you need to create one checkbox field and one lookup field.Now you can put above code in your class and page .click preview button on page you will see your solution.If it will work.Please mark it as a best answer.

If you will face any problem let me know.

Thanks,

Dileep

This was selected as the best answer
vishnu Rvishnu R

hi venkat,

we can't achieve this functionality as it is not available in salesforce till now....
we can update the lookup field but we can't disable the lookup.
By using validation we can check whether the lookup field can be empty or not by cjecking the true /false conditon of checkbox.

if you want this functionality vote for the following idea..https://success.salesforce.com/ideaView?id=08730000000hS2tAAE

please let us know if this helps you..

thanks 
vishnu R

kasa venkat 14kasa venkat 14
Thanks Dilip  it works,
@vishnu thanks for valuble feedback