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
SasszzSasszz 

i am a newbie

how to make a number  field(total units__c) as a read only, non editable and that field should have default value. for example , if (total units__c) is set to a default value 10.whenever a status__c(picklist) is selected as sold,the (total units__c) should decrease by 1
Best Answer chosen by Sasszz
Deepali KulshresthaDeepali Kulshrestha
Hi Sasszz,

To make this field read only, Click on

Setup ---> Customize ---> Objects ---> Page Layouts ---> Edit the page layout ---> Select field you want to make read only ---> Click on 'Properties' of the field(an icon to the right end of field) ---> Here you will get a checkbox to make the field read only.

Other way to make the field read only is -

Setup ---> Customize ---> Objects ---> Fields ---> Click on the field you want to make read only ---> Click on button 'Set field level security' ---> here make field read only for the profiles you want.

Define Default Field Values:-

1.Begin by creating a custom field; see Create Custom Fields. You can also define a default value for an existing custom field; see Edit Custom Fields.
2.Choose the type of field to create and click Next. For a list of the types available for default values, see Default Field Values.
3.Enter the attributes for the field.
4.Enter a default value or define a formula to calculate the default value.

Note Here you can write your condition by define the formula or you can write the validation rule according to your requirement(if (total units__c) is set to a default value 10.whenever a status__c(picklist) is selected as sold,the (total units__c) should decrease by 1). 

NOTE You can define a formula for default values only where appropriate. For example, the default value options for a checkbox field are limited to the options available for those types of fields, such as Checked or Unchecked.
For picklists, a valid formula result is either a constant or the API name of an entry in the Values list. The formula result has higher precedence than the default assigned in the Values list. If the formula doesn’t generate a valid result, the default assigned in the Values list is entered in the field. If a default is not assigned to the Values list, no value is entered in the picklist field.

5.Click Next.
6.Set the field-level security to determine whether the field should be visible for specific profiles, and click Next.
7.Choose the page layouts that should display the field. The field is added as the last field in the first two-column section on the page layout. For user custom fields, the field is automatically added to the bottom of the user detail page.
8.Click Save to finish or Save & New to create more custom fields.

NOTE You must specify a default value for required campaign member custom fields.
Don’t assign default values to fields that are both required and unique, because uniqueness errors can result.

Default Field Values:-
Default field values automatically insert the value of a custom field when a new record is created. You can use a default value on a formula for some types of fields or exact values, such as Checked or Unchecked for checkbox fields.

After you have defined default values:

1.The user chooses to create a new record.
2.Default field value is executed.
3.Salesforce displays the edit page with the default field value prepopulated.
4.The user enters the fields for the new record.
5.The user saves the new record.

The user can change the field’s value but the initial default field value is only executed once, during record creation. For example, you can set the default field value on a custom lead field to seven days after the creation date to signify when to contact the lead again. You can change this value later, but you cannot automatically restore the value that was seven days after the creation date.

Set up default field values for the following types of custom fields:

-Checkbox
-Currency
-Date
-Date/Time
-Email
-Number
-Percent
-Phone
-Picklist
-Text
-Text Area
-Time
-URL

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha

All Answers

ManojjenaManojjena
HI Sasszz,

In page layout make the field read only and in work flow update the field based on the picklist value .

Let me know if it helps !!
Thanks '
Manoj
SasszzSasszz
hi manoj,  
      is that possible in system administrator profile?
Deepali KulshresthaDeepali Kulshrestha
Hi Sasszz,

To make this field read only, Click on

Setup ---> Customize ---> Objects ---> Page Layouts ---> Edit the page layout ---> Select field you want to make read only ---> Click on 'Properties' of the field(an icon to the right end of field) ---> Here you will get a checkbox to make the field read only.

Other way to make the field read only is -

Setup ---> Customize ---> Objects ---> Fields ---> Click on the field you want to make read only ---> Click on button 'Set field level security' ---> here make field read only for the profiles you want.

Define Default Field Values:-

1.Begin by creating a custom field; see Create Custom Fields. You can also define a default value for an existing custom field; see Edit Custom Fields.
2.Choose the type of field to create and click Next. For a list of the types available for default values, see Default Field Values.
3.Enter the attributes for the field.
4.Enter a default value or define a formula to calculate the default value.

Note Here you can write your condition by define the formula or you can write the validation rule according to your requirement(if (total units__c) is set to a default value 10.whenever a status__c(picklist) is selected as sold,the (total units__c) should decrease by 1). 

NOTE You can define a formula for default values only where appropriate. For example, the default value options for a checkbox field are limited to the options available for those types of fields, such as Checked or Unchecked.
For picklists, a valid formula result is either a constant or the API name of an entry in the Values list. The formula result has higher precedence than the default assigned in the Values list. If the formula doesn’t generate a valid result, the default assigned in the Values list is entered in the field. If a default is not assigned to the Values list, no value is entered in the picklist field.

5.Click Next.
6.Set the field-level security to determine whether the field should be visible for specific profiles, and click Next.
7.Choose the page layouts that should display the field. The field is added as the last field in the first two-column section on the page layout. For user custom fields, the field is automatically added to the bottom of the user detail page.
8.Click Save to finish or Save & New to create more custom fields.

NOTE You must specify a default value for required campaign member custom fields.
Don’t assign default values to fields that are both required and unique, because uniqueness errors can result.

Default Field Values:-
Default field values automatically insert the value of a custom field when a new record is created. You can use a default value on a formula for some types of fields or exact values, such as Checked or Unchecked for checkbox fields.

After you have defined default values:

1.The user chooses to create a new record.
2.Default field value is executed.
3.Salesforce displays the edit page with the default field value prepopulated.
4.The user enters the fields for the new record.
5.The user saves the new record.

The user can change the field’s value but the initial default field value is only executed once, during record creation. For example, you can set the default field value on a custom lead field to seven days after the creation date to signify when to contact the lead again. You can change this value later, but you cannot automatically restore the value that was seven days after the creation date.

Set up default field values for the following types of custom fields:

-Checkbox
-Currency
-Date
-Date/Time
-Email
-Number
-Percent
-Phone
-Picklist
-Text
-Text Area
-Time
-URL

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha
This was selected as the best answer