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
Raj R.Raj R. 

How to allow users to modify a field that is not on the page layout?

Hi,

We currently have two buttons on the Contact page layout, Activate and Deactivate. When the Deactivate button is pressed, a custom hidden field, Deactivated__c, is set to TRUE. When the Activate button is pressed, then the custom Deactivated__c field is set to FALSE. Upon clicking of either buttons, the user is redirected to a custom VisualForce (VF) page. Upon successful load of the VF page, the Deactivated__c field is to TRUE when user clicks on Deactivate and Deactivated__c field is set to FALSE when the user clicks on the Deactivate button.

Here is the caviot, regular users cannot see the field because it is not on the page layout. It is essentially a hidden field on the backend that is set.

The problem is that when the field is placed onto the page layouts, the users are able to click both buttons and the flag is set to TRUE and FALSE depending upon action. When the field is removed from the page layout (current situation), the users are not allowed to update that field even though I have provided them appropriate access to the VF page. 

I need help if figuring out how I can hide the field and still be able to set the Deactivated__c field to TRUE or FALSE depending upon which button is clicked. 
 
Best Answer chosen by Raj R.
Raj R.Raj R.
I figured out the issue. During reactivation, I was not calling Database.Update(this.Contact), so I when was pressing Activate the field was not updated even though I thought it was. 

The solution was to add a function on the VF page that does something along the lines of the following below (for simplicity i did not use direct syntax).

<button onclick="activate();>Activate </button>

Contact.activate(){
this.Contact.Deactivated__C = false;
Database.Update(this.Contact);
}

Thanks Aditya for the quick response.

All Answers

Aditya312Aditya312
Can you please share you vf code. There is vf tag <apex:inputHidden/>, try to use this tag for containing the field which you want to hide and using javascript code you can check/uncheck the value of checkbox field.
Raj R.Raj R.
I figured out the issue. During reactivation, I was not calling Database.Update(this.Contact), so I when was pressing Activate the field was not updated even though I thought it was. 

The solution was to add a function on the VF page that does something along the lines of the following below (for simplicity i did not use direct syntax).

<button onclick="activate();>Activate </button>

Contact.activate(){
this.Contact.Deactivated__C = false;
Database.Update(this.Contact);
}

Thanks Aditya for the quick response.
This was selected as the best answer