function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
dbrucedbruce 

Help troubleshooting trigger test class with FIELD_FILTER_VALIDATION_EXCEPTION

I have a simple update trigger that populates a related lookup and works fine but fails in the test class. The error is "FIELD_FILTER_VALIDATION_EXCEPTION". Looking through the logs I see an earlier SOQL statement that looks like the trigger's tempvar1 is not being properly populated. Does anyone have any insight on this?

Here is the object, code and coverage information:

Parent Object: Agreement__c with fields: ID, Name, Account__c (lookup), etc...
Child Object: Approved_Product__c with fields: ID, Name, Agreement__c(lookup), Account__c(lookup), etc...

Trigger to update Approved_Product__c.Account__c when Approved_Product__c.Agreement__c is entered:

trigger getAcct4AppvdProdTrigger on Approved_Product__c (before insert, before update){
   set<Id> agreementIdSet = new set<Id>();
   for(Approved_Product__c ap: trigger.new){
      if(ap.Agreement__c != null){
         agreementIdSet.add(ap.Agreement__c);
      }
   }
   map<id, Agreement__c> AgreementMap = new map<id, Agreement__c>([
      SELECT id, Account__c
      FROM Agreement__c
      WHERE Id IN: agreementIdSet
   ]);
   for(Approved_Product__c ap: trigger.new){
      if(AgreementMap.containsKey(ap.Agreement__c)){
         ap.Account__c = AgreementMap.get(ap.Agreement__c).Account__c;
      }      
   }
}

Test Class:

@isTest
private class Test_Trigger_ApprovedProductAccount {
   static testMethod void testApprovedProductAccountTrigger() {

//FIRST create test data
   Account a = new Account(Name='TestApProdTriggers Account-A');
   insert a;
   Account b = new Account(Name='TestApProdTriggers Account-B');
   insert b;
   Agreement__c p = new Agreement__c(
      Name='TestRenewTrigger Parent',
      Account__c = a.ID
   );
   insert(p);
//END Create test data. BEGIN tests
   Approved_Product__c ap = new Approved_Product__c(
      Name='TestAcctTriggers ap',
      Agreement__c = p.ID
   );
   insert(ap);   
   System.debug('Verifying getAcct4AppvdProdTrigger.trigger updated the account to ID '+ap.ID);
   ap = [
      SELECT Account__c
      FROM Approved_Product__c
      WHERE ID = :ap.ID
   ];
   System.assertEquals(a.ID,ap.Account__c,'Account not inserted. getAcct4AppvdProdTrigger.trigger failed');
   }
}

Selected Log Info (in decending order): 

15:55:37:462 FATAL_ERROR 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.: [Agreement__c]

15:55:37:420 CODE_UNIT_FINISHED getAcct4AppvdProdTrigger on Approved_Product trigger event BeforeInsert for [new]

15:55:37:416 SOQL_EXECUTE_BEGIN [22]|Aggregations:0|select id, Account__c from Agreement__c where Id = :tmpVar1


Observation: 
Am I possibly not instanciating tmpVar1 properly in my test class?
Best Answer chosen by dbruce
@anilbathula@@anilbathula@
Hi dbruce,

I think the Agreement__c lookup field has some filter condition on it.
Check the filter condition and pass the test class data according to the filter condition.
I hope it works.

Thanks
Anil.B

All Answers

@anilbathula@@anilbathula@
Hi dbruce,

I think the Agreement__c lookup field has some filter condition on it.
Check the filter condition and pass the test class data according to the filter condition.
I hope it works.

Thanks
Anil.B
This was selected as the best answer
dbrucedbruce
Hi Anil.B, Thank you for your reply. I found no validation rules on that field in either the Agreement object or the Approved Product object. I also found no filters in the lookup relationship on that field in either object. Is there somewhere else I should look?
dbrucedbruce
Besides validation rules and lookup filters are there other validation criteria I should look for?
dbrucedbruce
Oh Gee. I just didn't look in the right place. It was indeed a lookup filter. Thank you, @anilbathula@