You need to sign in to do that
Don't have an account?

FIELD_FILTER_VALIDATION_EXCEPTION error on testMethod
Hi,
I am trying to modify one of my test methods to make sure that it complies with some validation rules I recently created. I also added a lookup filter on the Decision_Maker__c field (lookup on the Contact) so users can only look up Contact that are related to Account that Opportunity is related to. So if Account A had two contacts, if I create an Opportunity and want to add the Decision Maker field, I only want to be able to find the two contact that Account A has in the lookup filter. Here's my logic for the filter:
Decision Maker: Account ID equals Field Opportunity: Account ID (required filter)
This is the error that I am getting:
System.DmlException: Insert failed. First exception on row 0; first error: FIELD_FILTER_VALIDATION_EXCEPTION, Value does not exist or does not match filter criteria.: [Decision_Maker__c]
I'm confused because I am pretty sure the Contact that I create in the Unit Test is related the Account I create. Then the Opportunity I create is related to the Account, so I'm confused on why it's tripping up the error since I related everything together on the original Account.
public static testMethod void TestCreateActualsAndTargets_Trigger(){ Account l_oAccount = new Account(Name='TestAccount', Type='Eligible'); insert l_oAccount; User testUser = TestFactory.buildTestASUser(0, 'Standard User'); insert testUser; Contact testContact = new Contact (); testContact.FirstName='Testo'; testContact.LastName='Westo'; testContact.Account=l_oAccount; insert testContact; Opportunity l_oOpportunity = new Opportunity(); l_oOpportunity.Name='Test Opportunity'; l_oOpportunity.Type = 'New Ad Sales'; l_oOpportunity.CloseDate=System.today(); l_oOpportunity.StageName='Closed/Won'; l_oOpportunity.AccountId=l_oAccount.Id; l_oOpportunity.ForecastCategoryName='Pipeline'; l_oOpportunity.Contract_ID__c = '123173'; l_oOpportunity.Multiple_Contract_IDs_at_Close__c = 'No - I have one single Contract'; l_oOpportunity.Split__c = '50/50'; l_oOpportunity.User__c = testUser.Id; l_oOpportunity.Report_Generation_Tools_Reviewed_withSP__c = 'Yes'; l_oOpportunity.Personality_of_ServiceProvider__c = 'Yes'; l_oOpportunity.SPs_Expectations__c = 'Yes'; l_oOpportunity.Why_We_Gave_SpecialPricing__c = 'Yes'; l_oOpportunity.UpsellOpportunities__c = 'Yes'; l_oOpportunity.Advertising_Contact__c = testContact.Id; l_oOpportunity.SP_knows_grade_and_current_revie__c = 'Yes'; l_oOpportunity.Decision_Maker__c = testContact.Id; l_oOpportunity.SP_verbally_agreed_to_specific_coupon__c = 'Yes'; l_oOpportunity.Length_of_SalesCycle__c = 'Within a Week'; insert l_oOpportunity; }
All Answers
Perfect! Thanks for your help!