0

I have the following validation rules that should validate whether an Account has a 'complete' address when an opportunity is created for the account, and they're not validating and I'm not sure why. I have them listed under validation rules for opportunities.

Validation rule 1:

AND(
    ISPICKVAL(StageName, "Award Close 100%"), 
    (LEN( Account.Street_Address__c )=0), 
    (LEN( Account.City__c )=0))

Validation rule 2:

AND( 
    ISPICKVAL(Account.Country_Code__c, "United States"), 
    OR( 
        LEN( Account.State_Province__c ) < 2, 
        NOT( 
            CONTAINS("AL:AK:AS:AZ:AR:CA:CO:CT:DE:DC:FL:FM:GA:GU:HI:ID:" & 
            "IL:IN:IA:KS:KY:LA:ME:MH:MD:MA:MI:MN:MS:MO:MT:NE:NV:NH:" & 
            "NJ:NM:NY:NC:ND:MP:OH:OK:OR:PW:PA:PR:RI:SC:SD:TN:TX:UT:VT:VA:" & 
            "VI:WA:WV:WI:WY:AE:AA:AP", Account.State_Province__c ) 
    )))

We have old data in our system where some accounts don't have full addresses and we wanted to make sure the account stays up to date.

  • AND(ISPICKVAL(StageName, "Award Close 100%") Do you create opportunities that are closed? Maybe remove that criteria. – frontendloader Apr 22 '15 at 18:10
  • Yeah, the criteria is met properly.. Thanks for the input. – user3708392 Apr 22 '15 at 18:14
  • Might be that the cross object reference doesn't work in that context, in which case you would need to perform your validation in a before insert/before update trigger. – Adrian Larson Apr 22 '15 at 21:14
  • shot in the dark - account.country_code__c is being tested for "United States" and not "US" ? When faced with these issues, I break down the validation rule into simpler bits (comment out clauses) and make sure each condition is working as expected; making adjustments as needed – cropredy Apr 23 '15 at 1:26
  • How about creating two Checkbox formulas on the Opportunity object, with exactly the same formulas as the validation rules? Named 'Violates validation rule 1 (or 2)' Than you can see, for existing Opportunities, if those formulas work the way you expect them to. – Sander de Jong Apr 23 '15 at 12:57
1

I have already experienced, that the child object (in your case the opportunity) does not yet have access to the parent object's (in your case the account's) fields by the time the validation rule is run. I would recommend using a simple before trigger to perform validation.

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.