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
Admin User 3354Admin User 3354 

Error during deployment of test class.

Hello,
I am facing the following Error: " TestAttendanceUpdateTaxi.TestinsertAttendance(), Details: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, No Existing Campaign Product found, request you to generate it manually.: [] Class.TestAttendanceUpdateTaxi.TestinsertAttendance: line 53, column 1" during deplyment when i validate the following trigger.

Test Class:

@isTest

public class TestAttendanceUpdateTaxi
{
  private  static testMethod void TestinsertAttendance()
    {
    
    
        //Inserting Records for Company Obj(Accounts).
        ////Fetching Record Type for Company Obj
        RecordType rt1 = [select id, Name from RecordType where SobjectType = 'Account'  AND Name='Sherbet'];
        Account account = new Account();
        account.recordTypeId = rt1.id;
        account.Name= 'Test Account';
        insert account;

        //Insering into Opportunity
       Opportunity o=new Opportunity();
       o.Name='Test2';
       o.AccountId=account.Id;
       o.CloseDate=date.today();
       o.Order_Reference__c = 'test1212';
       o.StageName='6 Signed deal';
       insert o;
      
   //Inserting Record for Taxi Obj
       //Fetching Record Type for Taxi Obj
        RecordType rt = [SELECT id, Name FROM RecordType WHERE SobjectType='Taxi__c' AND Name='Sherbet'];
        Taxi__c OTaxi = new Taxi__c();
        OTaxi.recordTypeId=rt.id;
        OTaxi.Name = 'Tx912';
        OTaxi.Company__c = account.id ;
        OTaxi.Last_Attended_Date__c = System.today();
        insert OTaxi;
        
        //Retrive inserted Taxi
        OTaxi = [select Name from Taxi__c where Id =: OTaxi.Id];
        System.debug('Taxi Registration No :'+ OTaxi.Name);
        
        
        //Inserting record for Attendance Object
       Driver_Payment__c OAttendance = new Driver_Payment__c();
        OAttendance.Campaign__c = o.id;
        OAttendance.Company_Name__c = account.id;
        OAttendance.Taxi_ID__c = OTaxi.id;
       OAttendance.Attended_Date__c = System.today();
       OAttendance.Update_current_receipt_campaign__c = True;
       OAttendance.Update_current_Superside_Livery_Campaign__c = True;
     //  OAttendance.Update_current_Tip_seat_campaign__c = True;
       
       insert OAttendance;
       
        System.debug('Inserted values in Attendance obj');
       //updating attendance
    
         //Updating Values   
        OAttendance.Update_current_Tip_seat_campaign__c = True;
       update OAttendance;
       
        
        //Assert
       Taxi__c ObjTaxi = [select Last_Attended_Date__c from Taxi__c where Name = 'Tx912' and Taxi__c.Company__c =: account.Id /*'001q000000JwBJT'*/ limit 1];
      System.assertEquals(OAttendance.Attended_Date__c , ObjTaxi.Last_Attended_Date__c);
    }
}


There are no validation rules on any object except opportunity.
Also I can't understand why it is asking me to create campaign product.
Urgent help is needed as my deployment is stuck because of single trigger.
Thanks.
KaranrajKaranraj
This error occurs when there is a validation rule and one of the test methods is hitting exception caused by a validation when creating/updating a test record.  The solution is to modify the record(s) in the DML operation such that they comply with the validation rule. The validation rule is there for a reason, so it should be obeyed. Turning off the validation rule temporarily isn't advisable, as it means the test method isn't reflective of the correct production schema, and hence neither is your Apex code.

First identify in which object yo have validation rule with the error message "No Existing Campaign Product found" and update your test data in your test class to match the validation rule condition.
James LoghryJames Loghry
For what it's worth, it might not be a validation rule, but rather a trigger or process that is causing the exception to be thrown.  I would take a look at your Opportunity, Taxi, and Driver Payment objects to look for any triggers that might complain when no existing campaign product is found.  From there, it's likely you'll figure out that you'll need to create a "Campaign Product" record in your unit test and associate it somewhere with that particular record.
Admin User 3354Admin User 3354
Thanks a lot both of you. It really heled me. As James said yes it was trigger that caused me error,