0

i have an requirement , i have field like quantity it is number field and i have a field like batch number it is text field , and i have written a validation rule on batchnumber with regex function ,the format is "bb:1#cc:2#dd:6" and my requirement is if i entered in quantity field ex 30 and the batch number it will only accept the format like "bb:10#cc:10#dd:10" means it has to add the quantity and enter in batchnumber , both fields it should have the quantity and batchnumber is to equal when they add both the fields can any one let me know the solution for this .

Regards, Teja.

7
  • How are you populating both of these two fields? manually while creating the record? and what will happen if you delete any of these two field values? – Salesforcesmarty Dec 4 '15 at 6:35
  • Hi , it is populated by manually by user if we delete the field value it cant be submitted – user16869 Dec 4 '15 at 12:48
  • Hi , i have written the validation rule on batch number by using regex function , were can i place your below code in below validation rule can you pls help on this – user16869 Dec 7 '15 at 5:57
  • my validation rule is AND($RecordType.DeveloperName ="Return", ISPICKVAL($User.PFE_Country__c,"PR") , (NOT(REGEX(PFE_Batch_Number__c,"[a-zA-Z0-9]{1}[a-zA-Z0-9]*[:][0-9]{1}[0-9]*"))), (NOT(REGEX(PFE_Batch_Number__c,"[a-zA-Z0-9]{1}[a-zA-Z0-9]*[:][0-9]{1}[0-9]*[#][a-zA-Z0-9]{1}[a-zA-Z0-9]*[:][0-9]{1}[0-9]*"))), (NOT(REGEX(PFE_Batch_Number__c,"[a-zA-Z0-9]{1}[a-zA-Z0-9]*[:][0-9]{1}[0-9]*[#][a-zA-Z0-9]{1}[a-zA-Z0-9]*[:][0-9]{1}[0-9]*[#][a-zA-Z0-9]{1}[a-zA-Z0-9]*[:][0-9]{1}[0-9]*")))) – user16869 Dec 7 '15 at 5:57
  • please place the below code in properly pls send it to me . – user16869 Dec 7 '15 at 5:58
0

Given that your REGEX can validate the Batch Number format, I find that to develop the Validation Rule I use several formula fields for readability and then a simple Validation Rule. This makes debugging easy and the resulting VR is easy to follow for the next admin who takes over your work.

Five formula fields:

FirstColonIx__c

FIND(':',  Batch_Number__c )

SecondColonIx__c

FIND(':',  Batch_Number__c  , FirstHashIx__c)

ThirdColonIx__c

FIND(':',  Batch_Number__c , SecondHashIx__c)

FirstHashIx__c

FIND('#',  Batch_Number__c)

SecondHashIx__c

FIND('#', Batch_Number__c, FirstHashIx__c+1 )

Validation Rule

(
VALUE(MID( Batch_Number__c , FirstColonIx__c+1, FirstHashIx__c-FirstColonIx__c-1)) +

VALUE(MID( Batch_Number__c , SecondColonIx__c+1, SecondHashIx__c-SecondColonIx__c-1)) +

VALUE(MID( Batch_Number__c , ThirdColonIx__c+1,  LEN( Batch_Number__c) - ThirdColonIx__c  ))

) 

<> Quantity__c

Of course, you could do this all in APEX trigger in a lot less code but you asked for a formula

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.