+ Start a Discussion
champ_vimalchamp_vimal 

Custom Field Validation Exception - Test Method error

Hello All,

 

I am writing a test method for a trigger and it gives me failure error during run test saying that there is some custom field validation exception. 

 

The exact failure message is : 

 

'System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, No Step 1 provider is tagged to this job centre: [Jobcentre_Plus__c]'

 

Please note there is no such validation rules in any of objects I have used in test method. But after going through some information from test method articles, I have even corporated  Dml Exception failure using try catch statements and that error disappears!

 

Now I have different error while running test. It gives me REQUIRED_FIELD_MISSING error at line 54 col 3 for Job_Seeker_Case__c field in Action Plan Object record insert even though I have given the value to it.

 

My questions are:

 

1) How can I fix my code?

2) What is the significance of CUSTOM FIELD VALIDATION error even if we have no validations on any of objects concerned?

 

Request you to please assist me in this!

 

Here is the code:-

 

public class testTrgActionAfterUpdateInsert
{
 static testMethod void trgActionAfterUpdateInsertMethod()
 {
  Jobcentre_Plus__c JCP = new Jobcentre_Plus__c(Phone__c='456676',Town_City__c='Mumbai', Street__c='420', region__c = 'Wales',Jobcentre_Plus_Office_Code__c='Off Code 1',JCP_Advisor_Name__c='Vimal Desai',Name = 'Job Centre 1', County__c='Maharashtra',Postcode__c='98765');
  try {
       insert JCP;
      }
     
      catch (DmlException e)
       {
            //Assert Error Message
            System.assert( e.getMessage().contains('Insert failed. First exception on ' +
                'row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION'),
                e.getMessage() );
              }

 
  Account JS = new Account(FirstName= 'Jose',LastName= 'Aquilani',NI_Number__c = 'JC522826C',Town_City__c='Mumbai', Street__c='200',County__c='Ker',Postcode__c='12141',Preferred_Method_of_Communication__c='Letter');
  //insert JS;
   try {
       insert JS;
      }
     
      catch (DmlException e)
       {
            //Assert Error Message
            System.assert( e.getMessage().contains('Insert failed. First exception on ' +
                'row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION'),
                e.getMessage() );
              }
 
  Date date1 =Date.newInstance(2009,08,12);
 
  Provider__c PRO = new Provider__c(name = 'Pro1', Contractor_No__c = 'Cr - 102', Contract_No__c = 'C - 102', Step__c = '2', Can_Claim__c = 'Yes', Type__c = 'tbc',  Street__c = 'Strt - 1', Town_City__c = 'Mumbai', County__c = 'County 1', Postcode__c = 'Post Code - 1', Main_Contact__c = JS.OwnerId);
  insert PRO;

  Job_Seeker_Case__c JSC =  new Job_Seeker_Case__c(Job_Seeker__c=JS.id,DWP_PO_No__c='Dwp-123',Jobcentre_Plus__c=JCP.id,Date_of_Referral__c=date1, Step_1_Provider__c = PRO.id);
  //insert JSC;
 
   try {
       insert JSC;
      }
     
      catch (DmlException e)
       {
            //Assert Error Message
            System.assert( e.getMessage().contains('Insert failed. First exception on ' +
                'row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION'),
                e.getMessage() );
              }

  Action_Plan__c actPlan = new Action_Plan__c(Action_Plan_Start_Date__c = date1, Status__c = 'In Progress', Frequency_of_Contact__c = 'Once a Week', Agreed_Number_of_Weekly_Job_Applications__c = 32, Job_Seeker_Case__c = JSC.id);
  insert actPlan;
 
  Action__c actn = new Action__c(Action_Plan__c = actPlan.id, Status__c = 'In Progress', Action_Owner__c = 'act own 1');
  insert actn;
 
  System.assertEquals(actPlan.Actions_Last_Updated_Date__c, System.Today());
 
 }
}

 

Thanks,

 

Vimal

 

 

champ_vimalchamp_vimal

Can anyone please assist me in this?

 

Thanks,

 

Vimal

saharisahari

Hey vimal,

I got the same exception. My trigger was on Leads. So I checked my code. it was all correct, So went back to the object and checked existing records.

I had an already existing record in Leads object that was actually vioalating my trigger.

This record was created prior to the trigger creation.

So just made small correction and it all worked out fine. 

Probably you might also have the same prob