You need to sign in to do that
Don't have an account?

Trigger is Failing Validation Rule, Can't Figure Out Why
My test class runs this code:
test.starttest(); insert Css; Css[1].Disbursement_Destination__c = Null; Css[3].Disbursement_Destination__c = Null; Css[5].Disbursement_Destination__c = Null; Css[1].Existing_or_New_Disbursement_Destination__c = 'Use/Create a New Disbursement Destination'; Css[3].Existing_or_New_Disbursement_Destination__c = 'Use/Create a New Disbursement Destination'; Css[5].Existing_or_New_Disbursement_Destination__c = 'Use/Create a New Disbursement Destination'; update Css; system.debug('Updated Css'); test.stoptest();
which is causing this validation rule to fail:
AND( OR( ISPICKVAL( Existing_or_New_Disbursement_Destination__c , 'Leave Disbursement Destination Blank'), ISPICKVAL( Existing_or_New_Disbursement_Destination__c , 'Use/Create a New Disbursement Destination') ), Disbursement_Destination__c <> Null)
despite the fact that the code (attempts to) set the value of Disbursement_Desintation__c to Null.
Any insight as to why this validation rule is failing?
Thanks!
So, the validation rule evaluates to AND( OR( false, true), false), right? And that's false.
When you say the rule is failing, are you saying that it's allowing the records to be updated?
I'm still learning the platform, but is "<> Null" treated the same as "!= Null"?
Have you tried changing the rule to be just the ISPICKVAL OR and then just the Null check to isolate which of the two tests is failing?
When I say failing, I meant that it is NOT allowing the records to be updated, but because test case sets the field to Null, it should ALLOW the record to be created.
As far I know, <> and != are the same.
Thanks!
Is your AND/OR logic correct?
It sounds like the field can only be NULL if the pick is one of two values. So, a non-null Disbursement Destination is always valid, and a null destination is OK for both of the pick vals, right? If that's the case, then it should be a three-way OR instead of the outer AND.
That's fine. Maybe I don't understand the business logic. Aren't you trying to handle the following:
rowValid = (Disbursement_Destination__c != NULL)
|| (Existing_or_New_Disbursement_Destination__c == 'Leave Disbursement Destination Blank')
|| (Existing_or_New_Disbursement_Destination__c == 'Use/Create a New Disbursement Destination')
So, that looks like all OR logic to me -- no AND.
Sorry, I forgot that validation rules need to be TRUE to indicate an error, not to indicate a valid record. The problem with your logic is that the inner OR is returning TRUE instead of FALSE when either of the pickvals is selected (the proper logic for your business rule).
Use either of the following:
Generate an error if the pick val is not "leave blank" AND it is not "create new" AND the destination is Null.