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
Max Friel.ax1251Max Friel.ax1251 

Force an inputfield to be editable...

Is it possible to for an apex:inputField element to be editable even if the user viewing the page has read only access to it?  I don't actually want to write the change back to the record, simply want an input field there of the correct type based on the field with the records info already filled in. 

Best Answer chosen by Admin (Salesforce Developers) 
Max Friel.ax1251Max Friel.ax1251

Alright, so solution.  Not perfect but its getting the job done.  I made one field for every possible field type is my request change object, and ran an input field on that, then triggered it on Upsert to look for what field was populated and move that value into one field.  I think had to have a map of String to String that contained the type of the original field and mapped it to the name of hte field on the change request...

 

<apex:inputField rendered="{!IF(aci['Type__c'] == 'PICKLIST' || aci['Type__c'] == 'MULTIPICKLIST','false','true')}" label="{!aci['Field_Label__c']}" value="{!aci[fldLookup[aci['Type__c']]]}"/>

 aci is the var containing the change request object.  I am having a bit of trouble sorting out the last bit of the picklists, but as you can see i handled them separately.

All Answers

TarentTarent

i think it's not possible.

Starz26Starz26

If they are not going to edit it use outPutfield

MaxFrielMaxFriel

They can edit it but it won't be going back into the record it came from.  The VisualForce page is supposed to be a type of change request, which the users can't edit the data directly, but I will be creating a change request out of it that will be passed along.

sfdcfoxsfdcfox

FLS (Field Level Security) is strictly observed in Visualforce. If they can't edit the field normally, they can't edit it on your page. You'll have to use a different object/field, or allow them to edit the field; you can use validation rules if you'd still like to remind users that they can't actually edit a field manually, such as:

 

AND(NOT(ISNEW()),PRIORVALUE(MyField__c)<>MyField__c)

 

MaxFrielMaxFriel

The issue here is that the value is being saved in a field that is just a plain text field.  So I want things like the lookups,picklists and date picker to still have the correct field input attached to them but if I used the destination field as the value for the inputField, I would lose those things. 

sfdcfoxsfdcfox

You just need to make sure they can edit the source field. I understand that you're copying values from one place to another, but the reality is that you can't edit a field you can't edit. You could create a fake intermediary object that you could use as a place holder for the inputField elements. There's plenty of ways to "get around" FLS, you just need to be a little creative.

MaxFrielMaxFriel

They can't edit the source field, thats why they this whole thing is in place.  To allow them to submit a request to change that data, if they were allowed to edit that data directly they wouldn't need to submit a change request. 

Starz26Starz26
sfdcfox made a good suggestion, create a secondary object that mirrors the original. Optionally, give them ability to edit the fields. Assign them a page layout that is ready only. That way when viewing the original they can't edit, but when viewing the VF page they can. The downside is that if the access via API (ETL Tool) they can edit the fields. Most users will not know how to do this though.
MaxFrielMaxFriel

Yea i also don't like the idea of having a duplicated object, especially considering this has been designed to be as expandable as possible and needing to go through the effort to duplicate every object we may want to use it for in the future.  Currently it is being used on four objects, if there was only a more dynamic way of selecting fieldsets it wouldn't have table names hardcoded anywhere into it. 

Max Friel.ax1251Max Friel.ax1251

Alright, so solution.  Not perfect but its getting the job done.  I made one field for every possible field type is my request change object, and ran an input field on that, then triggered it on Upsert to look for what field was populated and move that value into one field.  I think had to have a map of String to String that contained the type of the original field and mapped it to the name of hte field on the change request...

 

<apex:inputField rendered="{!IF(aci['Type__c'] == 'PICKLIST' || aci['Type__c'] == 'MULTIPICKLIST','false','true')}" label="{!aci['Field_Label__c']}" value="{!aci[fldLookup[aci['Type__c']]]}"/>

 aci is the var containing the change request object.  I am having a bit of trouble sorting out the last bit of the picklists, but as you can see i handled them separately.

This was selected as the best answer