0

I have Custom Object called "Review", with the formula field as

(Culture_fit__c  +  Experience__c  +  Leadership_Skills__c  
 + IF(
         Recommend_For_hire__c, 5, 1
     ) 
) /4. 

with Number data type

(Culture_fit__c  +  Experience__c  +  Leadership_Skills__c ) 

given value as (18,0) to all 3 data types.

My requirement is, without changing a value in datatype, I have to restrict the value to less than (10,0) to each field using the "Validation Rule". When a user tries to enter a value in New Record it should restrict the user to enter less than 10 Value in each field and calculate as per Formula expression.

  • 2
    I'd advise not marking an answer as accepted so quickly (especially if it doesn't answer your question). Doing so will signal to most people that your question has been resolved, and you'll be unlikely to receive any further answers. – Derek F Jul 27 '18 at 12:57
  • Are you trying to limit the entry to 10 digits (i.e., "5555694084" would be valid), or the numbers zero to ten (i.e, "4" and "10" would be valid)? – David Reed Jul 27 '18 at 13:53
  • Hi David, I am trying to enter the number as ( 0 to 10 ) in all there fields (Culture_fit__c + Experience__c + Leadership_Skills__c ) and caluculate as per formula :(Culture_fit__c + Experience__c + Leadership_Skills__c + IF( Recommend_For_hire__c, 5, 1 ) ) /4. – Sasi Chowdary Jul 27 '18 at 14:35
3

I would push back on this requirement. Although there are ways we can restrict field length in a validation rule, the more appropriate place to do this is in the field definition itself.

Taking data constraints out of the field definition violates the principle of least astonishment.

If you're dead set on doing this the hard way (i.e. using a validation rule), the documentation on formula functions will be indispensable. You'd probably need to use text() to turn your number into a string, and regex() to verify that there are 0 decimals (i.e. no "." in the resulting string).

You could probably use ^\\d{0,10}$ as the regular expression.

Honestly though, fight to keep this as part of the field definition.

| improve this answer | |
0

As per your question given field length is 18,0 but when user trying to enter more than 10 numbers it should throw error. correct? and you have to control all the 3 fields.

Please see below for validation rule and update your Field API name instead of NumberOfEmployees and update the restrict count which you have required.

LEN( TEXT(NumberOfEmployees)) > 10
| improve this answer | |
  • 2
    This is commentary posted as an answer. Once you have sufficient reputation you'll be able to comment under any question. Please visit the Help center to better understand how our forum works. – crmprogdev Jul 27 '18 at 12:35
  • Yes understood, I need to clarify with his question that's the reason I have posted here as don't have more reputation. – Prem Anandh Jul 27 '18 at 12:42
  • 1
    I have updated the answer, please check and update your result here – Prem Anandh Jul 27 '18 at 13:02
  • 1
    I understand, and once you earned 50 points of reputation, you'll be able to comment below any question. We appreciate those who follow the rules of the forum. Its not a good use of senior members time having to "police" our rules in these review queues. We could just automatically delete, but try to be nice about it. – crmprogdev Jul 27 '18 at 13:19
  • 2
    While your suggested validation rule will work in some situations, it will fail to stop decimals from being entered. – Derek F Jul 27 '18 at 13:30
0

The validation rule for a Number field having a value between 0 and 10 is very simple:

OR(My_Field__c < 0, My_Field__c > 10)

It can be made to apply to more than one field by repeating these comparisons in additional OR() arguments:

OR(My_Field__c < 0, My_Field__c > 10, My_Other_Field__c < 0, My_Other_Field__c > 10, ...)

Changing the data type would not help you in this case even if you could: you can set the number of decimals available on the field, but can't constrain the values further. Setting the data type to 2 places would only clamp the value at 99.

| improve this answer | |

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.