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
Rst123Rst123 

FIELD_FILTER_VALIDATION_EXCEPTION, Value does not exist or does not match filter criteria.: [Account__c]

HI,

I'm getting the below 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.: [Account__c]
I have highlighted the method below i'm getting the error :-
I have a master Look field Account__c on object :VVLOC__c
Criteria : -Account Record TypeequalsPartner Record Type

Code :-


@IsTest(SeeAllData=False)


   private class TestCreditApprovalUtility {
   
    static testmethod void testCalculateAppRemAmount()
      {
            Set<String> caOwnerId = new Set<String>();
      User u;
       Account a;
      User thisUser = [ select Id,UserRole.Name,Profile.Name from User where Id = :UserInfo.getUserId() ];
           //UserRole r = [select id,UserRole.Name,Profile.Name from User where id = :caOwnerId]; 
         System.runAs ( thisUser ) {
  

         Profile p = [SELECT Id FROM Profile WHERE Name='Standard User'];
        
      u = new User(Alias = 'standt', Email='standarduser@testorg.com',userroleid = thisUser.UserRole.Id,
      EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US',
      LocaleSidKey='en_US'
      , ProfileId = p.Id ,TimeZoneSidKey='America/Los_Angeles', UserName='standarduser@testGE.com');

          insert u;
          }
          Set<Id> AccountId = new Set<Id>();      
          Set<Id> ParentId = new Set<Id>();
      Set<Id> OpIds = new Set<Id>();

      Set<Id> CaIds = new Set<Id>();
       List<Credit_Approval__c> CAList= new List<Credit_Approval__c>();
       List<Credit_Approval__c> CreditLineList= new List<Credit_Approval__c>();

                              //Opportunity[] opps=[Select Credit_approval__c from Opportunity where Id in :caopps.keyset()];
        //Account account = [Select Id,Name,ParentId from Account where Id in :AccountId];      
        //Create test account
       
        List<Account> acct = new List<Account>();
        Account account = new Account();
         account.recordtype=new recordtype(name='Customer Record Type');
        account.Name = 'Test';
        account.BillingStreet = '123 Some St.';
        account.BillingCity = 'Somewhere';
        account.BillingState = 'CT';
        account.BillingPostalCode = '12345';
        account.ParentId = account.Id;
        System.runAs(u) {
         
        insert account;
        }

       
        // Create a new Partner Account
        Account partner = new Account();
        partner.recordtype=new recordtype(name='Partner Record Type');
        partner.Name = 'Test Partner';
        partner.BillingStreet = '123 Some St.';
        partner.BillingCity = 'Somewhere';
        partner.BillingState = 'CT';
        partner.BillingPostalCode = '12345';
        insert partner;
      
        // Create a test opportunity to associate with Credit Approvals and Quote
        List<Opportunity> OpList= new List<Opportunity>();
        Opportunity opportunity = new Opportunity();
        opportunity.OwnerId = userinfo.getUserId();
        opportunity.AccountId = account.Id;
        opportunity.Name = 'Test';
        opportunity.StageName = 'Lead';
        opportunity.CloseDate = Date.today();
        opportunity.Amount=1000;
        
        OpList.add(opportunity);    
        insert OpList;
       
               
        for(Opportunity o : OpList){
            OpIds.add(o.Id);
        }
        //Changes made for Audit Cleanup :Increase test class coverage
        //Creating test Quote
        Quote__c quote= new Quote__c();
        quote.Product__c='FMV';
        quote.Opportunity__c=opportunity.id;
        quote.Include_For_Risk__c=true;
       
        insert quote;
       
        //End of Changes made for Audit Cleanup :Increase test class coverage
       
        //Create test takedowns to associate with opportunity
        List<Takedown__c> takedowns= new List<Takedown__c>();
        Takedown__c Tk1= new Takedown__c();
        Tk1.Name= 'Test T1';
        Tk1.Opportunity__c= opportunity.id;
        Tk1.CurrencyIsoCode= 'USD';
        Tk1.Total_Amount_Financed__c=1000.00;
       
        takedowns.add(Tk1);
       
        Takedown__c Tk2= new Takedown__c();
        Tk2.Name= 'Test T2';
        Tk2.Opportunity__c= opportunity.id;
        Tk2.CurrencyIsoCode= 'USD';
        Tk2.Total_Amount_Financed__c=700.00;
       
        takedowns.add(Tk2);
       
        insert takedowns;
       
        Utility.isOwnerUpdate=true;
        Utility.IsStageChange=true;
                 
       
                       

                   
              
      }
     
     
      // =========Second test method================
             static testmethod void testCreditApproval()
    {
    Set<Id> OpIds = new Set<Id>();
    Set<Id> CaIds = new Set<Id>();
   Account account = new Account();
   Account partner = new Account();
   Opportunity opportunity = new Opportunity();

     List<Credit_Approval__c> CAList= new List<Credit_Approval__c>();
       List<Credit_Approval__c> CreditLineList= new List<Credit_Approval__c>();

     //Create test Credit Approvals
          Credit_Approval__c CA1=new Credit_Approval__c();
        CA1.Partner__c=partner.id;
        CA1.Account__c=account.id ;
        CA1.recordtype=new recordtype(name='EF HFS Credit Approval Record Type');
        CA1.Approved_Amount_With_Tolerance__c= 10000;
        CA1.Approved_Amount__c= 10000;
        CA1.Application_Type__c= 'Line Of Credit';
        CA1.Submittal_Status__c= 'Decisioned';
        CA1.Risk_Decision__c='Approved';
        CA1.LOC_Adjustment_Amount__c= 200.00;
        //CA1.Approval_Expiration_Date__c= myDate;
        CAList.add(CA1);
       
       
        Credit_Approval__c CA2=new Credit_Approval__c();
        CA2.Partner__c=partner.id;
        CA2.Account__c=account.id ;
        CA2.recordtype=new recordtype(name='EF HFS Credit Approval Record Type');
        CA2.Approved_Amount_With_Tolerance__c= 100.00;
        CA2.Approved_Amount__c= 10000;
        CA2.LOC_Adjustment_Amount__c= 200.00;
        CA2.Application_Type__c= 'Line Of Credit';
        CA2.Submittal_Status__c= 'Referred';
        CA2.Risk_Decision__c='Approved';
        //CA2.Credit_Line_ID__c= creditLine2.id;
        //CA2.Approval_Expiration_Date__c= myDate;
        CAList.add(CA2);
       
        Credit_Approval__c CA3=new Credit_Approval__c();
        CA3.Partner__c=partner.id;
        CA3.Account__c=account.id ;
        CA3.recordtype=new recordtype(name='EF HFS Credit Approval Record Type');
        CA3.Approved_Amount_With_Tolerance__c= 100.00;
        CA3.Approved_Amount__c= 10000;
        CA3.LOC_Adjustment_Amount__c= 200.00;
        CA3.Application_Type__c= 'Deal - Multiple Takedown';
        CA3.Submittal_Status__c= 'Test';
        CA3.Risk_Decision__c='Approved';
        //CA3.Credit_Line_ID__c= creditLine2.id;
        //CA3.Approval_Expiration_Date__c= myDate;
        CA3.Opportunity__c=opportunity.id;
        CAList.add(CA3);
       
        Credit_Approval__c CA4=new Credit_Approval__c();
        CA4.Partner__c=partner.id;
        CA4.Account__c=account.id ;
        CA4.recordtype=new recordtype(name='EF HFS Credit Approval Record Type');
        CA4.Approved_Amount_With_Tolerance__c= 10000.00;
        CA4.Approved_Amount__c= 10000;
        CA4.LOC_Adjustment_Amount__c= 200.00;
        CA4.Application_Type__c= 'Deal - Multiple Takedown';
        CA4.Submittal_Status__c= 'Decisioned';
        CA4.Risk_Decision__c='Approved';
        //CA4.Credit_Line_ID__c= creditLine2.id;
        //CA4.Approval_Expiration_Date__c= myDate;
        CA4.Opportunity__c=opportunity.id;
        CAList.add(CA4);      
        
        insert CAList;
       
           for(Credit_Approval__c c : CAList){
            CaIds.add(c.Id);
        }
           

    //Create test Credit Approvals to make them as child Credit Approvals
        Credit_Approval__c creditLine1 =new Credit_Approval__c();
        creditLine1.Account__c=account.id ;
        creditLine1.recordtype=new recordtype(name='EF HFS Credit Approval Record Type');
        creditLine1.Application_Type__c= 'Deal - Multiple Takedown';
        creditLine1.Approved_Amount_With_Tolerance__c= 1000.00;
        creditLine1.Approved_Amount__c= 200.00;
        creditLine1.Submittal_Status__c= 'Decisioned';
        creditLine1.Risk_Decision__c='Approved';
        creditLine1.Credit_Line_ID__c= CA1.id;
       
        CreditLineList.add(creditLine1);
       
        Credit_Approval__c creditLine2 =new Credit_Approval__c();
        creditLine2.Account__c=account.id ;
        creditLine2.recordtype=new recordtype(name='EF HFS Credit Approval Record Type');
        creditLine2.Application_Type__c= 'Deal - Multiple Takedown';
        creditLine2.Approved_Amount_With_Tolerance__c= 100.00;
        creditLine2.Approved_Amount__c= 200.00;
        creditLine2.Submittal_Status__c= 'Referred';
        creditLine2.Risk_Decision__c='Approved';
        creditLine2.Credit_Line_ID__c= CA2.id;
        creditLine2.LOC_Adjustment_Amount__c= 200.00;
       
        CreditLineList.add(creditLine2);
       
        Credit_Approval__c creditLine3 =new Credit_Approval__c();
        creditLine3.Account__c=account.id ;
        creditLine3.recordtype=new recordtype(name='EF HFS Credit Approval Record Type');
        creditLine3.Application_Type__c= 'Deal - Multiple Takedown';
        creditLine3.Approved_Amount_With_Tolerance__c= 100.00;
        creditLine3.Approved_Amount__c= 200.00;
        creditLine3.Submittal_Status__c= 'Referred';
        creditLine3.Risk_Decision__c='Approved';
        creditLine3.Credit_Line_ID__c= null;
        creditLine3.LOC_Adjustment_Amount__c= 200.00;
       
        CreditLineList.add(creditLine3);     
               
        insert CreditLineList;

    Test.startTest();
        //CA1.Approved_Amount_With_Tolerance__c= 20000;
        //update CAList;
              
        Map<Id,Decimal> UsedAmt= CreditApprovalUtility.GetUsedAmounts(CaIds);
        List<Credit_Approval__c> ca = [Select Id,Amount_Approved_Remaining__c from Credit_Approval__c where Id in :CaIds];
        Map<Id,decimal> RemAm= CreditApprovalUtility.CalculateAppRemAmount(null);
        Map<Id,decimal> RemAmount= CreditApprovalUtility.CalculateAppRemAmount(CAList);
        //system.assertEquals(9800.00,RemAmount.get(CA1.id));
         Map<Id,decimal> RemAmountt= CreditApprovalUtility.CalculateAppRemAmount(CreditLineList);
       
        //Changes made for Audit Cleanup :Increase test class coverage
        Map<Id,double> PaymentStreamTerm= CreditApprovalUtility.GetPaymentStreamTerm(OpIds);
        //system.assertEquals(0.0,PaymentStreamTerm.get(opportunity.id));
        //End of Changes made for Audit Cleanup :Increase test class coverage
       
        Test.stopTest();

    }
    static testmethod void testCreditApproval1()
  {
  Credit_Approval__c CA=new Credit_Approval__c();

  set<id> recordtypeids=new set<id>();
  recordtype rectyp = new recordtype();
   Set<Id> OpIds = new Set<Id>();
    Set<Id> CaIds = new Set<Id>();
    Set<Id> AccountId = new Set<Id>();      
      Set<Id> ParentId = new Set<Id>();
      Set<Id> OpId = new Set<Id>();
     Set<Id> CAPartnerIds = new Set<Id>();

   Account account = new Account();
   List<Account> acct = new List<Account>();
        //Account account = new Account();
         account.recordtype=new recordtype(name='Customer Record Type');
        account.Name = 'Test';
        account.BillingStreet = '123 Some St.';
        account.BillingCity = 'Somewhere';
        account.BillingState = 'CT';
        account.BillingPostalCode = '12345';
        account.ParentId = account.Id;
                
        insert account;

   Account partner = new Account();
   Opportunity opportunity = new Opportunity();
  
       List<Credit_Approval__c> CAList= new List<Credit_Approval__c>();
       List<Credit_Approval__c> CreditLineList= new List<Credit_Approval__c>();
     VVLOC__c vloc = new VVLOC__c();
     vloc.Account__c = Account.ID; 
     vloc.Vendor_Loc_Status__c = 'INA'; 
      vloc.Name = vloc.Id; 
      vloc.Vendor_Location__c ='Test';
      account.ParentId = account.Id;
                     
      Insert vloc;
    
  }
  }
sfdc_ninjasfdc_ninja
It looks like you are trying to create new record types within your test methods, which you aren;t doing correctly, nor is it necesary.  See the documentaion here, recordtype data is availbe in TestClasses even if they have SeeAllData=false

https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_testing_data_access.htm

All you need to do is query for the record types ( I would do this into a Map with the name as the key).  Something like this

map<string, RecordType> rtMap = new map<string, RecordType>();
list<RecordType> rts = [Select Id, Name From RecordType Where SobjectType = 'Account' And isActive = true];
for(RecordType rt : rts){
     rtMap.put(rt.Name, rt.Id);
}

Then you can use the recordtypes in the test methods.  

Then you have to ensure that the Account and Partner account have the same RecordType (see below) and you should be all set.

myAccount.RecordTypeId = rtMap.get('record type name you want').Id;
partnerAccount.RecordTypeId = rtMap.get('same record type name').Id;
Rst123Rst123
Thanks for reply!!!  when i'm trying to do this way ...getting error  : Incompatible value type Id for MAP<String,RecordType>
map<string, RecordType> rtMap = new map<string, RecordType>();
list<RecordType> rts = [Select Id, Name From RecordType Where SobjectType = 'Account' And isActive = true];
for(RecordType rt : rts){
     rtMap.put(rt.Name, rt.Id);
}
Getting this error :-
Incompatible value type Id for MAP<String,RecordType>
sfdc_ninjasfdc_ninja
Oh yes, that's my mistake.  You need to add the recordtype, not the id.  Try this

list<RecordType> rts = [Select Id, Name From RecordType Where SobjectType = 'Account' And isActive = true];
for(RecordType rt : rts){
     rtMap.put(rt.Name, rt);
}