0

can I get some advise on below validation rule on Account? I have tried to change it multiple times, but it's not firing when it should.

When the User is trying to make an Account Active by unchecking inactive field, each different fields are required for each record to be checked if BLANK.

I'd also like to check if below is correct - val rule should fire when the value is either O or greater than 1 Count_of_Terms__c >=1

With record type IDs - should I remove last 3 digits?

My Validation Rule:

AND(
    NOT($Setup.Bypass_Settings__c.Validations__c),
    ISCHANGED(Inactive__c)

    /*RT 1*/
    AND(
        RecordTypeId = "0123X0000004FkY",
        OR(
            ISBLANK(Business_Name__c),
            ISBLANK(c2g__CODAAccountTradingCurrency__c),
            ISBLANK(c2g__CODAAccountsPayableControl__r.Name),
            ISBLANK(c2g__CODAAccountsReceivableControl__r.Name), 
            ISBLANK(c2g__CODABankAccountName__c),
            ISBLANK(BillingStreet), 
            ISBLANK(BillingPostalCode),
            ISBLANK(c2g__CODAInvoiceEmail__c), 
            ISBLANK(TEXT(c2g__CODAPaymentMethod__c),
            ISBLANK(TEXT(c2g__CODAVATStatus__c),
            Count_of_Terms__c = 0
        )
    ),

    /*RT 2*/
    AND(
        RecordTypeId = "0123X000000446Q",
        OR(
            ISBLANK(Business_Name__c),
            ISBLANK(c2g__CODAAccountTradingCurrency__c),
            ISBLANK( c2g__CODAAccountsReceivableControl__r.Name), 
            ISBLANK(c2g__CODABankAccountName__c),
            ISBLANK(BillingStreet), 
            ISBLANK(BillingPostalCode),
            ISBLANK(c2g__CODAInvoiceEmail__c), 
            ISBLANK(TEXT(c2g__CODAVATStatus__c)
        )
    ),

    /*RT 3*/
    AND(
        RecordTypeId = "0123X000000446R",
        OR(
            ISBLANK(Business_Name__c),
            ISBLANK(c2g__CODAAccountTradingCurrency__c),
            ISBLANK(c2g__CODAAccountsPayableControl__r.Name),
            ISBLANK(c2g__CODABankAccountName__c),
            ISBLANK(BillingStreet), 
            ISBLANK(BillingPostalCode),
            ISBLANK(c2g__CODAInvoiceEmail__c), 
            ISBLANK(TEXT(c2g__CODAPaymentMethod__c),
            ISBLANK(TEXT(c2g__CODAVATStatus__c),
            Count_of_Terms__c = 0
        )
    ),

    /*RT 4*/
    AND(
        RecordTypeId = "0123X000000446S",
        OR(
            ISBLANK(Business_Name__c),
            ISBLANK(c2g__CODAAccountTradingCurrency__c),
            ISBLANK(c2g__CODAAccountsPayableControl__r.Name),
            ISBLANK( c2g__CODAAccountsReceivableControl__r.Name), 
            ISBLANK(BillingStreet), 
            ISBLANK(BillingPostalCode),
            ISBLANK(c2g__CODAInvoiceEmail__c), 
            ISBLANK(TEXT(c2g__CODAVATStatus__c)
        )
    ),

    /*RT 5*/
    AND(
        RecordTypeId = "0123X0000004FkY",
        OR(
            ISBLANK(Business_Name__c),
            ISBLANK(c2g__CODAAccountTradingCurrency__c),
            ISBLANK(c2g__CODAAccountsPayableControl__r.Name),
            ISBLANK(c2g__CODABankAccountName__c),
            ISBLANK(BillingStreet),
            ISBLANK(BillingPostalCode),
            ISBLANK(c2g__CODAInvoiceEmail__c), 
            ISBLANK(TEXT(c2g__CODAPaymentMethod__c),
            ISBLANK(TEXT(c2g__CODAVATStatus__c),
            Count_of_Terms__c  = 0
        )
    )
)
2
  • Use RecordType.DeveloperName, not ids - also - 1 record can only be 1 RT yet you are using an outer AND - hence four of the five inner ANDs will be false, making the outer AND false
    – cropredy
    Commented Oct 19, 2022 at 15:59
  • Can you please advise where to put/remove the outer AND to make this validation rule work on all conditions and a particular record will only check if the account is inactive and then look for a condition relevant to that record? @cropredy Commented Oct 19, 2022 at 16:12

1 Answer 1

1

Your issue is because 1 record can only be 1 RT yet you are using an outer AND - hence four of the five inner ANDs will be false, making the outer AND false

You'll need to do something like this

AND (
    NOT($Setup.Bypass_Settings__c.Validations__c),
    ISCHANGED(Inactive__c),  /* Inactive field changed */   
    NOT(Inactive__c),        /* changed to unchecked */
    OR (
        AND(
            RecordType.DeveloperName = 'RT1',
            OR ( ...  /* fields can't be blank */
            )
        ),
        AND(
            RecordType.DeveloperName = 'RT2',
            OR ( ...  /* diff fields can't be blank */
            )
        ),       
        ...
     )  /* end of RT variations */
 )

Pro tip: Complex validation rules are best developed/ debugged incrementally - verify it works for a single recordtype, 1 non-blank, 1 blank field; then add more field checks; then add second recordtype, etc. Use comments in your VR as doc

1
  • Thank you @cropredy - I managed to figure out what it was :D I missing two parenthesis on below fields ISBLANK(TEXT(c2g__CODAPaymentMethod__c)), ISBLANK(TEXT(c2g__CODAVATStatus__c)) Commented Oct 20, 2022 at 8:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .