0

I have the following validation rule on contact:

OR(AND(MailingCountry = "Other Locations", ISPICKVAL(other_locations__c, "")), AND(NOT(MailingCountry = "Other Locations"), NOT(ISPICKVAL(other_locations__c, ""))))

and it works when I manually create a contact or convert a lead in to contact. But the problem is when I am doing an import with dataloader, with a record where both mailing address and other locations are empty it fails and I get this validation's error. In the settings of dataloader I have used insert null values. I even tried removing the columns mailing address and other locations, still the same error. Even with data wizard the same error.

2
  • 1
    Your title is misleading as the Validation Rule is working, you just need to bypass it in certain circumstances, e.g. upload via Data Loader. Do you have default values for the Picklist other_locations__c?
    – Dave Humm
    Commented Oct 23, 2020 at 10:25
  • other_locations__c does not have a default value
    – nSv23
    Commented Oct 23, 2020 at 10:30

1 Answer 1

1

If you want to bypass validation rules in certain contexts, a common approach is to use a dedicated user when running the Data Loader - let's call it [email protected].

Then rewrite your validation rule as:

$User.UserName <> '[email protected]' && 
OR(
   AND(MailingCountry = "Other Locations", 
       ISPICKVAL(other_locations__c, "")), 
   AND(NOT(MailingCountry = "Other Locations"), 
       NOT(ISPICKVAL(other_locations__c, "")))
)

A more sophisticated, and more useful approach would be to create a hierarchical custom setting, let's say Running_User_Settings__c with a field Is_Address_Validation_Disabled__c and when someone needs to bypass the validation on input, add a row in the Custom Setting for that user with the checkbox TRUE. Then your validation rule looks like this:

NOT($Setup.Running_User_Settings__c.Is_Address_Validation_Disabled__c) && 
OR(
   AND(MailingCountry = "Other Locations", 
       ISPICKVAL(other_locations__c, "")), 
   AND(NOT(MailingCountry = "Other Locations"), 
       NOT(ISPICKVAL(other_locations__c, "")))
)
3
  • why do I need to bypass the validation rule with data loader? shouldn't it follow the validation rule and work just like manual insertion of a record?
    – nSv23
    Commented Oct 27, 2020 at 8:13
  • I may have misunderstood the OP - I thought you wanted the validation rule to not execute in a Data Loader context
    – cropredy
    Commented Oct 27, 2020 at 21:10
  • I assumed the validation will work but it seems the only way is to bypass it. So like you suggested I have to disable it. But I am just curious why is it like that.
    – nSv23
    Commented Oct 27, 2020 at 21:17

You must log in to answer this question.

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