0

I have created a Validation Rule on the Opportunity that it's referencing Account Fields, but it doesn't work accordingly. I have changed it a few times.

I have created a picklist on the Opportunity:

Picklist__c with values:

a
b
c
d
  1. When Value = a is selected, I want the Validation Rule to check a custom field from the Account object to be "yes". The custom field on the Account is a dependent picklist with "yes" and "no" values.

    *If the custom field on the Account object is "yes", then the Opportunity can be created.
    
  2. When Value = b is selected, I want the Validation Rule to check the value of a lookup field (to Account) from the Opportunity to match the value of a lookup field on the Account (Self-Relationship field).If the lookup field on the Account is empty or doesn't match, the Opportunity can't be created.

  3. When Value = c is selected, I want the Validation Rule to check the value of a lookup field (to Account) from the Opportunity to match the value of a lookup field on the Account (Self-Relationship field). If the lookup field on the Account is empty or doesn't match, the Opportunity can't be created.

4.When Value = d is selected, I want the Validation Rule to check both custom fields on the Opportunity (from point 2 and 3) from the Opportunity to match the values of the lookup fields on the Account (from point 2 and 3). Also if the fields are empty, the Opportunity can't be created.

My VR on Opportunity:

    AND(

OR(
ISPICKVAL(Picklist__c, 'a'),
ISPICKVAL(Picklist__c, 'b'),
ISPICKVAL(Picklist__c, 'c'),
ISPICKVAL(Picklist__c, 'd'),

OR(

ISPICKVAL(Account.picklist__c, 'No'),
lookup1__c = Account.lookup1__c,
lookup2__c = Account.lookup2__c,
lookup1__c = Account.lookup1__c && lookup2__c = Account.lookup2__c

)

)
0

The problem is that your actual VR it's just cheking if values are a b c OR d are selected AND and any of the other conditions are true. You have to check conditions one by one with the pick list value selected.

Also, you are setting in the VR the logic that is correct, you have to set the incorrect values that make your VR fires, for example:

  • lookup1__c = Account.lookup1__c is correct and you want to let him create the record, you have to set in the VR what is incorrect and would make it fires: lookup1__c != Account.lookup1__c)

Just let me redact your conditions to give you an other point of view:

If any of this conditions happends, the VR must be fired:

  • When Value = a is selected and Picklist have "no" value.

    OR

  • When Value = b OR c OR d is selected, If the lookup field on the Account is empty or doesn't match.

    OR

  • When Value = d is selected, if the lookup fields are empty.

So your VR must be something like this:

OR(
   AND(
       ISPICKVAL(Picklist__c, 'a'),
       ISPICKVAL(Account.picklist__c, 'No')
   ),
   AND(
       OR(
          ISPICKVAL(Picklist__c, 'b'),
          ISPICKVAL(Picklist__c, 'c'),
          ISPICKVAL(Picklist__c, 'd')
       ),
       OR(
          ISBLANK(Account.lookup1__c),
          lookup1__c != Account.lookup1__c
       )
   ),
   AND(
       ISPICKVAL(Picklist__c, 'd'),
       OR(
          ISBLANK(lookup1__c),
          ISBLANK(Account.lookup1__c)
       ) 
   )
)

Remember, you allways have to set the values that makes the VR fires, not the correct values that lets create the record.

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.