+ Start a Discussion
bkradminbkradmin 

Field Filter Validation Exception

I am getting an error on a test class that I am not understanding: "First exception on row 0; first error: FIELD_FILTER_VALIDATION_EXCEPTION, Value does not exist or does not match filter criteria.: [Hospital__c]" 

 

Can anyone help?

 

Here is the test class:

 

@isTest
private class TestHospitalization {
static testMethod void myUnitTest() {
     //make Contact
     Date sdate1=date.today();
     sdate1=sdate1-1;
     Date sdate2=sdate1.addMonths(3);
        Contact NewCont = new Contact (FirstName='Test', LastName='Name');
       insert NewCont;
       Account NewAcct = new Account (Name='Test');
       insert NewAcct;
       Hospitalization__c NewHosp = new Hospitalization__c (Client__c=NewCont.Id, Hospital__c=NewAcct.Id,Date_of_admission__c=sdate1);
       insert NewHosp;
       Hospitalization__c NewHosp2 = new Hospitalization__c (Client__c=NewCont.Id, Hospital__c=NewAcct.Id,Date_of_admission__c=sdate2);
       insert NewHosp2;
       NewHosp.Bed__c='1';
       update NewHosp;
       NewHosp.Date_of_admission__c=sdate2;
       update NewHosp;
   }
}

 And here is the trigger:

 

trigger CurrentHospital on Hospitalization__c (after update,after insert) {
List <Contact> UpCont=new List <Contact>();
//List <Contact> TestCont=new List <Contact>();
List <Id> TestCont=new List <Id>();
List <Contact> YesCont=new List <Contact>();

Set <Contact> MyCont=new Set <Contact>();
Map <Id, Hospitalization__c> ContHosp=new Map<Id,Hospitalization__c>();
Contact thisCont=new Contact();
//Id thisCont=new Id();
for (Hospitalization__c l : Trigger.new) {
  //thisCont=l.Client__c;
  TestCont.add(l.Client__c);
}
if(TestCont.size()>0){
    List <Hospitalization__c> HasHosp=[SELECT Client__r.Name,Client__r.Hospitalization__c,Id,Currently_in_Hospital__c FROM Hospitalization__c WHERE Client__c IN :TestCont ORDER BY Currently_in_Hospital__c ASC];
        for (Hospitalization__c b: HasHosp){
          thisCont=b.Client__r;
          if(MyCont.contains(thisCont)){
             MyCont.remove(thisCont);
      }
        if(b.Currently_in_Hospital__c==0&&thisCont.Hospitalization__c!=null){
          thisCont.Hospitalization__c=null;
          MyCont.add(thisCont);
        } else if(b.Currently_in_Hospital__c==1) {
          thisCont.Hospitalization__c=b.Id;
          MyCont.add(thisCont);
        }
        
      }
      if(MyCont.size()>0){
      UpCont.addAll(MyCont);
      }
    /*for (Integer i=0; i < TestCont.size(); i++){
        if(TestCont[i].Hospitalization__c==null){
            UpCont.add(TestCont[i]);
        }
    }*/
}

  
if(UpCont.size()>0){
update UpCont;//all contacts should be updated one way or the other
}
}

 

Best Answer chosen by Admin (Salesforce Developers) 
kiran2000kiran2000

look for filter on Hospital__c field which is not satisfying in test classes...

All Answers

kiran2000kiran2000

look for filter on Hospital__c field which is not satisfying in test classes...

This was selected as the best answer
bkradminbkradmin

Thanks. I removed the filter and now its working fine. 

 

I guess it would be redunant for me to admit that I'm a rookie.