+ Start a Discussion

Why i can't pass in parameter to read-only field ?

Good day,


I working on controller, which pass parameter via URL to a custom object detail page's fields.


for instance :



Controller :
String accountMember = 'user1';
String accountMember2 = 'user2';

String URL = /a03/e?xxx111=accountMember&xxx222=accountMember2;
PageReference myCustomObjectPR = new PageReference(urlStr);




Custom object:

xxx111 is field id of accountMember and belong to text field type

xxx222 is field id of accountMember2 and belong to text field type


Problem :

accountMember fields are both read-only suppose, i do not see my parameter populate in fields until i make the field to visible on FLS


Question :

1. why the readonly field can't get the parameter ?

2. if i make the fields to visible now, how can i make the fields not editable ? i try using validaton rule with formula 

isChange(accountMember__c) , it doesn't prevent user to edit before it get save, the validation only check after the record saved, any hint on this ?

3. What are the best solution to handle my case ?




Read-only fields are read-only. If it were that easy to edit an uneditable field, then field-level security and page field security would be pointless. If you must set a value, you have to use an "extension" to set the values at the controller level. You'd have to have a custom visualforce page, too, instead of depending on the standard new/edit page. You could also use "default values" to force a specfic default value for the field. Edit the field, and set and set the "default value formula" to fill in the value you'd like to use.