2

We've defined a custom field in our Tasks that is defined as a Number(8,4), our regional configuration is set to Spanish(Chile) where the thousand separator is period (.) and the decimal separator is a comma (,).

In the PC's keypad, which everyone uses heavily, there's a period and not a comma.

Programs like Excel automatically get the decimal separator from the regional configuration of the machine and replaces the period, obviously this is not the case with Salesforce or anything web related.

As this is typed inside the native Task layout, i cannot add jQuery to validate the input prior to saving or updating.

Validation rules and Triggers receive the inserted value post-processed, for example "1,2" in a trigger (after String.valueOf()) is received as "12".

So the short version of what we're trying to achieve is the following

  • 1.2 (invalid, some warning should appear)
  • 1,2 (valid, 1 is the integer part and 2 the decimal part)

Thanks in advance

2
  • what locale does the running SFDC user have defined? SFDC should do proper validation on input per running user's locale
    – cropredy
    Apr 17, 2015 at 2:37
  • Both organization and user are set to Español(Chile), my problem is that users use the period (as is right in the keypad) instead of comma, which is our decimal separator, i think SF validates just well as it interprets it as a thousand separator.
    – FuuRe
    Apr 17, 2015 at 15:04

2 Answers 2

0

If you're looking for a validation rule, you can use something like AND(CONTAINS(TEXT(fieldname), '.')) to to detect values like 1.2 and cause them to produce an error message. Note: I've assumed you'll need to put TEXT in front of the fieldname. Depending on the type of field, that may not be necessary.

In Apex, you mention String.valueOf(), its not clear to me how you're getting 12 from 1.2, but I've not worked with regional configs to have seen this. I'd think that the toString() method would give you 1,2 and you'd then be able to use some combination of String methods like contains(), replace('.',','), substringBefore('.'), substringBetween('.'), substringAfter('.') or indexOf('.') to either replace the periods or with commas or declare the data as invalid.

3
  • Thanks a lot but as i said this doesn't work, i've tried the contains in the validation rule just as you said. Can you try the other way? i mean typing "1,2" and then checking the value in a trigger, my guess is that you will get "12" thus rendering any before insert attempt to work with the value useless
    – FuuRe
    Apr 15, 2015 at 17:22
  • I just did an execute anonymous in the dev console of string.valueOf(decimal_variable) that had a value of 1.2 stored in it followed by a system.debug and it returned 1.2 which is what I would have expected it to return.
    – crmprogdev
    Apr 15, 2015 at 17:56
  • Should add that I can't test the 1,2 scenario since I can't put that into a decimal variable here.
    – crmprogdev
    Apr 15, 2015 at 18:21
0

In the end i went with creating string fields for the inputs and doing the validations in a "before insert, before update" trigger created only for this, and then assigning the validated values to their respective number fields.

I'm aware this isn't a direct answer to my problem, but this workaround solved my needs.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .