function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
agethuntagethunt 

hiding a field in pagelayout

i want to hide a field on the pageloaut depending upon the user. any help . i dont want to cretae any ne w pagelayot . in case it needs some javascript function help then let me know
Edwin VijayEdwin Vijay

In your normal pagelayout , you can hide fields using Field Level Security..

 

You will find "Set field level security" button when you view the details of a Field...

 

Is this what you're looking for? or you want to hide a field in a visualforce page....

agenthuntagenthunt
okay . leem give a real time example. just to point out , i am not adding any new profile and pagelayout 

 

 

two ways of doing things :

 

Scenario1

-------------

There are four  fields :A , B ,C ,D

 

if i want to  make 3 fields :B, C, D  visible depending upon the picklist value of   A , what should be done

 

 Scenario2
-------------

There are 2 types of user -A, B

 

when A logs in , he sees one set of fields and when B logs in he see another set of field . again , to make it clear i am not willing to have any FLS , profiles level permissions changed . ideally i would like one Jav script on top of a Visualfroce force form which decides on usr specific display of the fields. 
Edwin VijayEdwin Vijay

Ok...  But unfortunately you cannot embed a visualforce form or javascript into your normal page layout..

 

But you can very well create your own Visualforce Page...

 

There is a rendered attribute while you add fields to your visualforce page.. You can possible add any condition in this attribute (be it based upon user or anything)

 

Scenario 1 as well as 2 can be achieved using this..  Let me know if you need any help to get started

agenthuntagenthunt
Thanks Edwin . what about using  standard controller to create a section of field . and then in the pagelaout dragging this section . through the static resources , we can put one javascript , whichi will be header file for  visualforce page . long back i saw one JS function being use to hide certain field .  
Edwin VijayEdwin Vijay

Yes .. you can defenitely do it.. But my suggestion would be

 

1) Create a visualforce page with a standardcontroller


2) Use the rendered attribute and rerender attributes as far as possible..

 

If required use an extension

 

 

 

<apex:page standardcontroller="Campaign"> <apex:form > <apex:sectionHeader title="Create Campaign" subtitle="Create new Campaign"/> <apex:pageblock > <apex:pageBlockSection title="Campaign Information" columns="1"> <apex:inputfield value="{!Campaign.Name}" rendered="{!IF (CONTAINS($User.Alias, Smith) True, False)}"/> </apex:pageblocksection> </apex:pageblock> </apex:form> </apex:page>

 

Now, the Campaign name field will be displayed only if the current logged in User's alias name is "Smith"..

 

 

 

 

 


 

agenthuntagenthunt
somehow i am getting binding error . 
kaulsaksoftkaulsaksoft

Hi u can use the VisualForce DynamicPage Edit for the same where u can render few fields on the basis of the value that has been selected.

 

Rendering can be done on Picklist or checkbox or Button depending on the requirement.

 

agethuntagethunt
can u share the code with me . i am new to VF programming . another problem i am facing is the errors i am getting as binding errors . any help with that also would do
kaulsaksoftkaulsaksoft

Binding error are because there may be mismatch in the fields and the ids.

 

I am giving u the code for the same.

 

 

U can try the code for the Opportunity Object here u need to create two custom fields reason lost and competitor

 

<apex:page standardController="Opportunity" sidebar="false"> <apex:sectionHeader title="Edit Opportunity" subtitle="{!opportunity.name}"/> <apex:form > <apex:pageBlock title="Edit Opportunity" id="thePageBlock" mode="edit"> <apex:pageMessages /> <apex:pageBlockButtons > <apex:commandButton value="Save" action="{!save}"/> <apex:commandButton value="Cancel" action="{!cancel}"/> </apex:pageBlockButtons> <apex:actionRegion > <apex:pageBlockSection title="Basic Information" columns="1"> <apex:inputField value="{!opportunity.name}"/> <apex:pageBlockSectionItem > <apex:outputLabel value="Stage"/> <apex:outputPanel > <apex:inputField value="{!opportunity.stageName}"> <apex:actionSupport event="onchange" rerender="thePageBlock" status="status"/> </apex:inputField> <apex:actionStatus startText="applying value..." id="status"/> </apex:outputPanel> </apex:pageBlockSectionItem> <apex:inputField value="{!opportunity.amount}"/> <apex:inputField value="{!opportunity.closedate}"/> </apex:pageBlockSection> </apex:actionRegion> <apex:pageBlockSection title="Closed Lost Information" columns="1" rendered="{!opportunity.stageName == 'Closed Lost'}"> <apex:inputField value="{!opportunity.competitor__c}" required="true"/> <apex:inputField value="{!opportunity.Reason_Lost__c}"/> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>

 

 

 

 

I have used the same code for rendered the textboxes based on the checkbox selection in the code below.

 

For the page to execute Create an Object CustomerFinancialDetails

 

with the fields are mentioned in the code

 

 

<apex:page standardController="Customer_Financial_Details__c" tabStyle="Customer_Financial_Details__c"> <apex:form > <apex:pageBlock title="Customer Financial Detail Edit" id="thePageBlock"> <apex:pageBlockButtons > <apex:commandButton action="{!save}" value="Save"/> <apex:commandButton action="{!cancel}" value="Cancel"/> </apex:pageBlockButtons> <apex:actionRegion > <apex:pageBlockSection title="Liabilities" columns="2"> <apex:pageblockSectionItem > <apex:outputLabel value="Vechile Loan"/> <apex:outputPanel > <apex:inputCheckbox value="{!Customer_Financial_Details__c.Vechile_Loan__c}" id="theCheckbox"/> <apex:actionSupport event="onclick" rerender="thePageBlock" status="status"/> <apex:actionStatus startText="Please wait......." id="status"/> </apex:outputPanel> </apex:pageblockSectionItem> <apex:pageblockSectionItem > <apex:outputLabel value="Personal Loan"/> <apex:outputPanel > <apex:inputCheckbox value="{!Customer_Financial_Details__c.Personal_Loan__c}" id="theCheckbox"/> <apex:actionSupport event="onclick" rerender="thePageBlock" status="status"/> <apex:actionStatus startText="Please wait......." id="status"/> </apex:outputPanel> </apex:pageblockSectionItem> </apex:pageBlockSection> </apex:actionRegion> <apex:pageBlockSection title="Vechile Loan" columns="2" rendered="{!Customer_Financial_Details__c.Personal_Loan__c == true}"> <apex:pageblockSectionItem > <apex:outputLabel value="Vehicle loan monthly EMI"/> <apex:inputfield value="{!Customer_Financial_Details__c.Vehicle_loan_monthly_EMI__c}"/> </apex:pageblockSectionItem> <apex:pageblockSectionItem > <apex:outputLabel value="Total No of Years Of Loan"/> <apex:inputfield value="{!Customer_Financial_Details__c.Total_no_of_years_of_vehicle_loan__c}"/> </apex:pageblockSectionItem> <apex:pageblockSectionItem > <apex:outputLabel value="Total No of Years Pending"/> <apex:inputfield value="{!Customer_Financial_Details__c.Total_no_of_years_pending_for_vehicle__c}"/> </apex:pageblockSectionItem> <apex:pageblockSectionItem > <apex:outputLabel value="Year of final payment date"/> <apex:inputfield value="{!Customer_Financial_Details__c.Year_of_final_payment_date__c}"/> </apex:pageblockSectionItem> </apex:pageBlockSection> <apex:pageBlockSection title="Personal Loan" columns="2" rendered="{!Customer_Financial_Details__c.Vechile_Loan__c == true}"> <apex:pageblockSectionItem > <apex:outputLabel value="Personal loan monthly EMI"/> <apex:inputfield value="{!Customer_Financial_Details__c.Vehicle_loan_monthly_EMI__c}"/> </apex:pageblockSectionItem> <apex:pageblockSectionItem > <apex:outputLabel value="Total No of Years Of Loan"/> <apex:inputfield value="{!Customer_Financial_Details__c.Total_no_of_years_of_vehicle_loan__c}"/> </apex:pageblockSectionItem> <apex:pageblockSectionItem > <apex:outputLabel value="Total No of Years Pending"/> <apex:inputfield value="{!Customer_Financial_Details__c.Total_no_of_years_pending_for_vehicle__c}"/> </apex:pageblockSectionItem> <apex:pageblockSectionItem > <apex:outputLabel value="Year of final payment date"/> <apex:inputfield value="{!Customer_Financial_Details__c.Year_of_final_payment_date__c}"/> </apex:pageblockSectionItem> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>