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

Test Class problem
Hi, I have written a test class that keeps failing because of a FIELD_FILTER_VALIDATION_EXCEPTION. I have narrowed it down to the exact problem: Part of a lookup filter (that is looking up a Cash Account) specifies that returned records must have their Status__c = 'Active' (see full lookup filter below). When I remove this part of the filter lookup logic, the test class passes. When I add it back in, the test class fails again.
As you can see in my test class below, I have definitely set the Status__c for the Cash Account record insert to be 'Active'. So I just can't figure out what I'm missing that is causing the test class to fail based on this.
Any help much appreciated.
Lookup Filter:

Validation Error:

Test Class:
As you can see in my test class below, I have definitely set the Status__c for the Cash Account record insert to be 'Active'. So I just can't figure out what I'm missing that is causing the test class to fail based on this.
Any help much appreciated.
Lookup Filter:
Validation Error:
Test Class:
@isTest private class TestCashAccountRollUpCashIn {static testMethod void myUnitTest() {Profile pf = [Select Id from Profile where Name = 'System Administrator'];User u = new User(); u.FirstName = 'Test'; u.LastName = 'User'; u.Email = 'testuser@test123456789.com'; u.CompanyName = 'test.com'; u.Title = 'Test User'; u.Username = 'testuser@test123456789.com'; u.Alias = 'testuser'; u.CommunityNickname = 'Test User'; u.TimeZoneSidKey = 'America/Mexico_City'; u.LocaleSidKey = 'en_US'; u.EmailEncodingKey = 'ISO-8859-1'; u.ProfileId = pf.Id; u.LanguageLocaleKey = 'en_US'; insert u; system.runAs(u){ //Set RecordTypeId variable CA String strcaRecordTypeId = [Select Id From RecordType WHERE DeveloperName = 'Person' AND sobjectType = 'Cash_Account__c'].Id; //Insert a cash account Cash_Account__c ca = new Cash_Account__c(); ca.RecordTypeId = strcaRecordTypeId; ca.Name = 'Test Person'; ca.Status__c = 'Active'; insert ca; system.assertEquals(ca.Rollup_Cash_In__c, null); //Set RecordTypeId variable CT String strctRecordTypeId = [Select Id From RecordType WHERE DeveloperName = 'Person_to_Person' AND sobjectType = 'Cash_Transfer__c'].Id; //Test payments on insert Cash_Transfer__c ct1 = new Cash_Transfer__c(); ct1.RecordTypeId = strctRecordTypeId; ct1.Destination__c = ca.Id; ct1.Amount__c = 100; insert ct1; Cash_Account__c cau1 = [select Rollup_Cash_In__c from Cash_Account__c where Id = :ca.Id]; system.assertEquals(cau1.Rollup_Cash_In__c,ct1.Amount__c); //Test payments on update Cash_Transfer__c ct1u = [select Amount__c from Cash_Transfer__c where Id = :ct1.Id]; ct1u.Amount__c = 200; update ct1u; Cash_Account__c cau2 = [select Rollup_Cash_In__c from Cash_Account__c where Id = :ca.Id]; system.assertEquals(cau2.Rollup_Cash_In__c,ct1u.Amount__c); //Test payments on second insert Cash_Transfer__c ct2 = new Cash_Transfer__c(); ct2.RecordTypeId = strctRecordTypeId; ct2.Destination__c = ca.Id; ct2.Amount__c = 800; insert ct2; AggregateResult ag1 = [select sum(Amount__c) from Cash_Transfer__c where Destination__c = :ca.Id]; Cash_Account__c cau3 = [select Rollup_Cash_In__c from Cash_Account__c where Id = :ca.Id]; system.assertEquals(cau3.Rollup_Cash_In__c,ag1.get('expr0')); //Test payment on delete delete ct2; AggregateResult ag2 = [select sum(Amount__c) from Cash_Transfer__c where Destination__c = :ca.Id]; Cash_Account__c cau4 = [select Rollup_Cash_In__c from Cash_Account__c where Id = :ca.Id]; system.assertEquals(cau4.Rollup_Cash_In__c,ag2.get('expr0')); } } }
Thanks,
Maddy!
Sorry for delay in reply.
I found nothing wrong with code. I drill down with multiple possibilities by reproduing at developer account. However I will suggest to clean up existing data in object 'Cash Transfer' to adhere new lookup filter criteria for field 'Destination' (lookup for obejct 'Cash Account').
Existing will be possible cause of error message.
Thanks,
Mahadev
Thanks for having a look a this for me. Good to know that the code seems ok.
In terms of cleaning up existing records, since it seems to be the 'Active' part causing the trouble, that would mean I have to reactivate old accounts that are now Inactive, which doesnt really seem like a longterm solution. Is that what you mean?
Thanks again.
Do you think this is worth lodging a case with Salesforce?