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
SanchSanch 

Making field Read Only in standard page layout after overwriting the New Button

Hi All,

 

I have the following:

 

1. A child object called Review under Opportunity object.

2. I have a custom visualforce page which overwrites the New Button. It's purpose is to prepopulates couple of fields. 

3. One of the fields that I am prepopulating is called ReadOnlyTest__c. It is populated with the text 'Testing ReadOnly'

4. The user has full access to the object

5. On the page layout I have made the field read Only.

 

What I am trying to archieve is prepopulate the field ReadOnlyTest__c with the value 'Testing ReadOnly' and make that field not editable by the user. But the user has to visually see this field. 

 

I do know I can do this with custom visualforce page.  But my goal is to do this with standard page layout. I expected the text to be pre-pulated. But what happens is the page renders fine and it shows the field as read only, but the text 'Testing ReadOnly' is missing. It's just empty. Can someone help me with what I might be doing wrong here?

 

Sanch

AravindBabu512AravindBabu512

Hi,

 

Please correct me if I am wrong, The requirment is to overwrite the New button functionality so that you are able to prefill few fields and make them read only. Instead of a Visual force page to do this, you can use a formula field and have your prefill condition as the formula field's condition. The reason why i am suggesting this is, you are making the field read only so the user cant edit once the prefill is done on page load.

 

Please let me know if my understanding on your requirement is incorrect.

 

Thanks,

Aravind

SanchSanch

Hi Aravind,

 

You do understand the requirement correctly. But I don't think I can use a formula field here.  The values that I am pre-populating is not coming from the parent object. It is coming from objects that are related to the parent object and also through some other querying and calculations.  Also, how would use formula field to archieve this? Can you provide a sample? Thanks.

 

Sanch

 

AravindBabu512AravindBabu512

Hi,

 

I get your point. If the value is obtained from objects, using cross object formula we can get it. Salesforce lets us to access data across objects upto 5 levels I suppose. But your next statement says, you will get data from query and calculations. If you could be specific on the requirement we can conclude on what to use i.e, what sort of calculations are done, what objects do you query, how many records are anticipated as resultset. If you could provide such details, we can discuss and arrive at a solution.

 

Thanks,

Aravind.

SanchSanch

Pretty much this is how the objects and fields are:

 

Opportunity
	- Opportunity Doc
		- Doc Type (picklist)
		- Financial 
			- Field 1
			- Field 2
			- Field 3
			- Field 4
			- Field 5
			- Field 6
			- Field 7
			- Field 8
			- Field 9
	- Review
		- Field 11 = Field 1 of Financial where Doc Type in ('LOI' or 'LI')
		- Field 22 = Field 1 of Financial where Doc Type in ('LOI' or 'LI')
		- Field 33 = Field 1 of Financial where Doc Type in ('LOI' or 'LI')
		- Field 44 = Field 1 of Financial where Doc Type in ('LOI' or 'LI')
		- Field 55 = Field 1 of Financial where Doc Type in ('LOI' or 'LI')
		- Field 66 = Field 1 of Financial where Doc Type in ('LOI' or 'LI')
		- Field 77 = Field 1 of Financial where Doc Type in ('LOI' or 'LI')
		- Average = (Field 8 > 0 && Field 9 > 0) ? (Decimal) (Field 7/Field 9/ (Field 8/12)).setScale(2) : 0;
		

 The review object is the new object that I created and it's New Button is which I am overwriting. Hoe that explains it. 

 

Sanch.

SanchSanch

It seems if you use a formula field, that field will not show up on the New record creation page.