The data type of the custom field is Text(1).
ISBLANK('Custom_Field__c') || REGEX(Custom_Field__c, '[1-7]')
This formula will allow blank fields. Great 50% there. Although, it will also permits a number outside the desired range AND alpha characters. What gives? What am I doing wrong?
Thank you Salesforce Community, you're my only hope!
5 respuestas
Yes, all data in that field is currently valid. Up until now it was previously only populated by Apex. We've recently been given a requirement to allow editing of that field. Therefore, I'm trying to futureproof POBCAK errors.
I like the idea of changing datatype but that field is referenced in triggers, apex classes, and apex test classes. That would take some retoolilng to dereference, make the change, then rereference in code--all for a pesky formula. oh_how_i_love_sfdc.jpgI have tried, with a little modificaiton from your suggestion, the following formula:
NOT(ISBLANK(Custom_Field__c))
&&
NOT(ISNUMBER(Custom_Field__c) || VALUE(Custom_Field__c) < 1 || VALUE(Custom_Field__c) > 7)
It still let me save an 'a' as well as a '9' in the field. SMH. ¯\_(ツ)_/¯