[SalesForce] Validation error is not showing in visualforce page

i wrote two validation rules for the same visualforce page.i have four fields in my page
Max_Quantity__c, Asked_Quantity_Number__c, BatchQuantity_Number_c,unitprice_c

first validation rule on unit price:

if(($Profile.Id<>'00e90000000erfV'), 
 OR 
 ( 
   Unit_Price__c==000000, 
   Unit_Price__c<000000 
 ) 
 ,false)

and the error message is

"unit price should be grater than zero"

second validation rule on remaining three fields:

 if( 
  ($Profile.Name = "France User"), 
  OR( 
    Max_Quantity__c < Asked_Quantity_Number__c, 
    Asked_Quantity_Number__c < BatchQuantity_Number__c 
  ),false 
 )

and the error message is

"you should follow this rule Batch Quantity <=Asked Quantity <= Max Quantity "

The problem is when the first validation is failed it is showing error in the visual force page .it is showing error and it is corrected it is saving the record
but with the second validation is failed it is "not showing the error" and "it is not saving the record" .

can somebody tell me why it is not showing the second validation rule error ….
user do not why it is not saving the record without saving the record .i need that for the second validation rule also it has to show the error…

Best Answer

Not sure from your description, but I suspect your validation rule is not actually the conditions the way you want them to. It seems to me that you are using an IF() statement when you really do not need to. In the current setup of your rule

if( 
  ($Profile.Name = "France User"), 
  OR( 
    Max_Quantity__c < Asked_Quantity_Number__c, 
    Asked_Quantity_Number__c < BatchQuantity_Number__c 
  ),false 
 )

The way that the IF statemtne works is as follows

IF(logical_test, value_if_true, value_if_false)

You are saying that If the profile of the current user is 'France User', then the formula will evaluate to your OR statement. If the user is NOT a France user, then it will always return false. It will never look at the conditions in your OR statement. Perhaps this is what you are trying to do, but I'm thinking it isn't.

I think what you are trying to do is something more like this

AND(
     ($Profile.Name = "France User"), 
     OR(
          Max_Quantity__c < Asked_Quantity_Number__c, 
          Asked_Quantity_Number__c < BatchQuantity_Number__c 
     )
)

This now checks that the current user is a 'France User' ANd one of the 2 conditions you listed are true.

You generally don't need to use an IF() if all of your functions within the rules return a boolean. It becomes redundant and complicates the rule.

Even though your first rule works, you might want to use this construct for that rule as well.

Related Topic