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
fatmonkfatmonk 

Test trigger help

I am writing my first trigger test: cover =0% 

Message:

System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, You Must Enter A Charge: []

 

Stack Trace

Class.TestUpdateCharge.testChargeContractTrigger: line 6, column 1

 

 

 

1@isTest
public Class TestUpdateCharge {

static testMethod void testChargeContractTrigger(){
Charge__c c = new Charge__c (City__c = 'Oakland');
insert c;


c = [select id,contract__c,Opportunity__c from Charge__c where City__c = 'Oakland'];

System.assertEquals(null, c.contract__c);
System.assertEquals(null, c.Opportunity__c);

}

}

HariDineshHariDinesh

Hi,

 

The Error message clearly says the Insert is Failed, Because of some validation.

Here by the insert statement you have written in test method didn’t insert the record.

The reason might be a validation rule exists on that object or some other mandatory fields on that object to form a record.

Please check those and make sure to insert record (charge__c) with required/proper data.