function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
KarinGKarinG 

Validation rule ISNEW() && ISCHANGED

Hello,
I need assistance with a validation please.
The validation rule must fire, only when (1) criteria are met on a newly created records, or when any one of (2) two fields are changed, but not when the (2) two fields are both zero. It works fine on edited records, but not for new records. On new records the validation rule fires irrespective of whether the criteria are met

(1) AND(AND(RecordType.Name <> 'abc', 
RecordType.Name <> 'def', 
RecordType.Name <> 'gh', 
RecordType.Name <> 'ijk', 
RecordType.Name <> 'lmn') , 
Insured_Value_Accepted__c = False,
(OR(Insured_Value__c >= (RetailValue__c + ( RetailValue__c *10/100)), 
Insured_Value__c <= (RetailValue__c - ( RetailValue__c *10/100))
)))

(2) Insured_Value__c & RetailValue__c

My validation rule:
IF(AND( Insured_Value__c = 0, RetailValue__c = 0),
 False,
 IF( OR(ISCHANGED(Insured_Value__c),ISCHANGED(RetailValue__c),  ISNEW()) ,
  IF(AND(AND(RecordType.Name <> 'abc', 
RecordType.Name <> 'def', 
RecordType.Name <> 'gh', 
RecordType.Name <> 'ijk', 
RecordType.Name <> 'lmn') , 
Insured_Value_Accepted__c = False,
(OR(Insured_Value__c >= (RetailValue__c + ( RetailValue__c *10/100)), 
Insured_Value__c <= (RetailValue__c - ( RetailValue__c *10/100))
))), True, False) ,
 false) )

Any assistance would be greatly appreciated!
Best Answer chosen by KarinG
Deepak RathinaveluDeepak Rathinavelu
Hi Karin,

I have the following points:
 
IF(AND( Insured_Value__c = 0, RetailValue__c = 0),// are you sure its the "AND" and not "OR"
/*here for newly created records with Insured_Value__c and RetailValue__c = 0 would also come under this condition, as it would run for both new and old records hence validation rule would not show validation error as it gives 'FALSE', also what if the value is changed to 0 itself even then the validation error would not show.*/
False, 
IF( OR(ISCHANGED(Insured_Value__c),ISCHANGED(RetailValue__c),  ISNEW()) , //in case of isnew=true
  IF(AND(AND(RecordType.Name <> 'abc', // can you check the default record type, I am thinking the default is not
RecordType.Name <> 'def', //in the condition
RecordType.Name <> 'gh', 
RecordType.Name <> 'ijk', 
RecordType.Name <> 'lmn') , 
Insured_Value_Accepted__c = False,//if the default value of this field is false then it would be always true
(OR(Insured_Value__c >= (RetailValue__c + ( RetailValue__c *10/100)), // can you check the value of insured value
Insured_Value__c <= (RetailValue__c - ( RetailValue__c *10/100))//as this condition seems fine
))), True, False) ,
 false) )

I hope it helps

Regards,
Deepak Rathinavelu

 

All Answers

Deepak RathinaveluDeepak Rathinavelu
Hi Karin,

I have the following points:
 
IF(AND( Insured_Value__c = 0, RetailValue__c = 0),// are you sure its the "AND" and not "OR"
/*here for newly created records with Insured_Value__c and RetailValue__c = 0 would also come under this condition, as it would run for both new and old records hence validation rule would not show validation error as it gives 'FALSE', also what if the value is changed to 0 itself even then the validation error would not show.*/
False, 
IF( OR(ISCHANGED(Insured_Value__c),ISCHANGED(RetailValue__c),  ISNEW()) , //in case of isnew=true
  IF(AND(AND(RecordType.Name <> 'abc', // can you check the default record type, I am thinking the default is not
RecordType.Name <> 'def', //in the condition
RecordType.Name <> 'gh', 
RecordType.Name <> 'ijk', 
RecordType.Name <> 'lmn') , 
Insured_Value_Accepted__c = False,//if the default value of this field is false then it would be always true
(OR(Insured_Value__c >= (RetailValue__c + ( RetailValue__c *10/100)), // can you check the value of insured value
Insured_Value__c <= (RetailValue__c - ( RetailValue__c *10/100))//as this condition seems fine
))), True, False) ,
 false) )

I hope it helps

Regards,
Deepak Rathinavelu

 
This was selected as the best answer
KarinGKarinG
Hi Deepak,

Thank you so much for your assistance!
 
line01. The validation should not fire if both the values are zero, irrespective of whether it is a new record or existing record. 
line05. Could you please clarify what you mean with "can you check the default record type"?
line10. Correct
line11.This value is manually entered


Best regards,

 
Deepak RathinaveluDeepak Rathinavelu
Hi Karin,

Is the record type given specifically, when the new record is created. Cause if not the deafult record type is assinged, and that record type might be missing from the condition being checked.

Also when is the values given for:
Insured_Value_Accepted__c
Insured_Value__c
RetailValue__c

Cause, If the values are not given when the record is being created then the condition might be comparing zeros, which would also satify the condition.

Sample input for a new record would really be helpful.

Thanks.
KarinGKarinG
Hi Deepak,

Thank you for your valuable input and assistance!

I found a before insert trigger updating the RetailValue to 0 based on another field. So the user's value entered in this field was overwritten with a zero, which then subsequently fires the validation rule. 

This had me stomped!

Thanks again!
 
Deepak RathinaveluDeepak Rathinavelu
Hey Karin,

Good to now that the issue is solved, can you change the status as such.

Thanks,
Deepak Rathinavelu