I have an obj1 and field on it field1 and one profile Billing User.

When I click a Custom Button on obj1, it will check the field1 to true for all the profile. However, I want field1 such that it should read only from page layout but it edit from apex, only for Billing User Profile.

If we make field read only from Field Accessibility then this field will not update by apex. I want Field Editable by apex and read only for manually only for specific profile. (Note: I've 12 record type) how can I achieve this?

  • Do you only have one profile? Therefor this rule should always exist, rather than only existing for the Billing User Profile? – Nick Cook Jul 19 '16 at 6:59
  • I've multiple profile. but this should i want for only one profile – user29314 Jul 19 '16 at 7:00

Create a new page layout of object1 for bill user profile/specific profile and set the field1 to read only from the page layout settings. This will serve your purpose. Note that a sys admin can still edit that read only field.

For a field countryName in the screen shot, i have applied the same.

enter image description here

| improve this answer | |
  • I've 12 Record Type and thus 12 Page layout already So, It is a correct way in this condtion – user29314 Jul 19 '16 at 7:21
  • You may have associated page layout to the respecitve record type. As per your need you can edit the layout. I would recommend use the formula field , remove your field1 from the layout and show formula_field1. – s_saiyan Jul 19 '16 at 7:21

You have many workarounds here.

  1. On the page layout you have options to make it read only but will not work for system admin they can edit.

  2. Create a new formula field and refer this field and then display that field on UI and remove the old field from UI.

  3. Create new detail page using Visualforce and apex and override the standard page.

  4. Put validation on trigger and use a static variable in condition and set it to true initially now set this variable to false when you update from apex if any user will update from UI then it will give error.

You can use any of the above 4 methods in your use case.

| improve this answer | |

You can create validation rule to restrict user other billing users to update this checkbox. Also you can create separate permission sets for different users for which this field can be readonly.

| improve this answer | |
  • I want field update by apex class for Billing User Profile also. then it possible to update by apex as per your answer.? – user29314 Jul 19 '16 at 7:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.