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
Deepika Gupta 26Deepika Gupta 26 

Restrict user to fill data on field via code when certain condition are match

Hi All,
​I want that in my if statement like if(Field1==true) //this is a checkbox field

     Restrict user to fill the Field2 & Field3 //this two fields are picklist field

All this three fields are on same object that is "Acccount:" let me know how is it possible to achieve in apex code.
Hi Deepika,

For that you can add disable attribute to Field2 & Field3. So when Field1 is true, then user won't be able to fill up f2 and f3.

If you need more clarity, post your code or share with me on

Hi Deepika,

Please try this below code.

When field1 is checked and field 2 or field 3 having any value then add error message in the record.
  if(rec.Field2!=null || rec.field3!=null){
     rec.addError('You are not allowed to enter the value to this field');
if you have any other scenario for whihch you need this please do share the code or scenario.

If this helps you please let me know.