0

I've got a validation rule on the Account sObject that checks whether a field has been updated if another field is not blank.

AND( 
    NOT(ISBLANK(customID__c)), 
    OR( 
        ISCHANGED( BillingCity ),
        ISCHANGED( BillingCountry )
    ) 
)

Then in Apex I'm attempting to update just the customID__c

Account updateAccount = new Account(Id = 'existingaccountid');
updateAccount.put('customID__c', '1234');
update updateAccount;

My problem is, that the validation rule is firing, and it shouldn't be.

Any guidance on how to fix this?

4
  • 1
    Any triggers, workflows, processes?
    – sfdcfox
    May 10, 2018 at 15:56
  • Is your code executed in a trigger where you are putting value in customID__c? Because that will signify that you are having a value in there which triggers your VR per order of execution.
    – Jayant Das
    May 10, 2018 at 15:58
  • Right now the code is being executed inside a server side controller when a button is being clicked from a lightning component. May 10, 2018 at 16:12
  • There is a trigger, but I've disabled it and we're still seeing the error. May 10, 2018 at 16:15

3 Answers 3

2

Whether a field has been updated if another field is not blank.

So, if I understood correctly, it will validate if BillingCity is changed when CustomId__c is not blank, then it will show the error message.

It should be AND condition, instead of OR

AND( 
    NOT(ISBLANK(customID__c)), 
        ISCHANGED( BillingCity )
    )

Update as per comments

There should be triggers, processes, workflow rule or other actions must be going on during post update, as this validation rule is not firing at my DE when I update the customField__c.

You should put a debug log to trace this.

1
  • Apologies I took this and redacted it a bit. I've corrected the code above to be more representative. Yes, it will validate if the billing city or country is changed when customerID__c is not blank. May 10, 2018 at 16:10
1

I found the issue. Deeper in the validation rule was the following check.

AND( 
    NOT(ISBLANK(customID__c)), 
    RecordType.DeveloperName ='Transactional', 
    OR( 
        ISCHANGED( BillingCity ), 
        ISCHANGED( BillingCountry ), 
        ISCHANGED(customID__c),
    ) 
)
0

I had the same issue, but it was caused by State and Country picklists.

Any edit to the record was triggering ISCHANGED(BillingCountry) or ISCHANGED(BillingState), even though the user was not editing these fields.

From page 6: http://resources.docs.salesforce.com/228/10/en-us/sfdc/pdf/state_country_picklists_impl_guide.pdf

You can’t use display values in validation rules or workflow rules that use comparison formula functions. If your validation or workflow rules on state or country fields use BEGINS, CONTAINS, ISCHANGED, or REGEX, use ISPICKVAL with state and country code values in your comparison functions

You must log in to answer this question.

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