I'm using Salesforce Classic. I've created a custom object called Proposal. Users view/edit this object via a page layout. I've embedded a Visualforce page in the layout. However, the fields in the Visualforce page are editable when users are viewing the custom object. I'd like the Visualforce page to be in read only mode when users are not editing the custom object. Is this possible?

  • Does this page double as the edit page or a custom button/link? – sfdcfox Nov 17 '16 at 17:29
  • No, it contains some custom fields with functionality I can't reproduce using declarative development. Essentially, the user will change two field values and click a [Save] button to save the changes. – Michael Sobczak Nov 17 '16 at 17:44
  • It might be helpful if you share your markup...Can you not simply use <apex:outputField> instead of <apex:inputField>. I don't quite follow when you would want these fields to be editable in your custom page. – Adrian Larson Nov 17 '16 at 17:49
  • When a user is viewing a standard object, they've clicked on a link to view it from a view list. The Standard Object is in what I would call "read mode". When the user clicks the Edit button at the top of the page layout, all of the fields in the page layout are displayed as input fields. Does that help? – Michael Sobczak Nov 17 '16 at 18:17
  • But the Visualorce Page is not displayed in edit mode, no? – Adrian Larson Nov 17 '16 at 20:12

To display a page in read-only mode you can use page attribute as follows:

<apex:page controller="myController" readOnly="true">

Secondly, change the <apex:inputField> to <apex:outputField>

Other advantage is query limit is getting increased from 50,000 rows to 1,000,000 rows.

While Visualforce pages that use read-only mode for the entire page can’t use data manipulation language (DML) operations, they can call getter, setter, and action methods which affect form and other user interface elements on the page, make additional read-only queries, and so on

Also, Visualforce controller methods with the @ReadOnly annotation automatically take advantage of read-only mode.

For more information refer Setting Read-Only Mode for an Entire Page

and Setting Read-Only Mode for Controller Methods


You can create a routing page, which will make the decision if editable or read-only page to be displayed.

Lets's say routing page is = VFRouting.page

In this page onload, you can take the URL and decide if this is to be navigated to read-only page or editable page.

Create 2 visualforce pages one for read-only and other for editable

And finally embed the VFRouting.page in page layout.

  • Thanks for your answer, but it doesn't address the problem I have. – Michael Sobczak Nov 17 '16 at 23:44
  • updated my answer – Santanu Boral Nov 17 '16 at 23:56
  • Thanks for the update, but your answer still doesn't address the issue I have. The Visualforce page is being displayed within a Custom Object page layout. I don't have control over the links the user uses to open the Standard Object. – Michael Sobczak Nov 18 '16 at 0:03
  • my solution will work I know – Santanu Boral Nov 18 '16 at 0:07
  • urls are different in view mode and edit mode, edit mode will have '/e' appended after recordId – Santanu Boral Nov 18 '16 at 0:08

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.