[SalesForce] Display visual force page in read only mode when custom object is being viewed

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?

Best Answer

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

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

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

Update

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.