You need to sign in to do that
Don't have an account?
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
@isTest
public Class TestUpdateCharge {
static testMethod void testChargeContractTrigger(){
Charge__c c = new Charge__c (City__c = 'Oakland');
insert c; <-- line 6
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);
}
}
Thanks,
Hi,
You have custom Validation for some field, so before inserting the object "c", populate it with all the required values.
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.
updated same at below
http://boards.developerforce.com/t5/General-Development/Test-trigger-help/td-p/484671
Thanks,
When i insert the Requiment I have a different error msg but Stack trace is line 6.
Msg:
System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Opportunity__c]: [Opportunity__c]
Stack Trace:
Class.TestUpdateCharge.testChargeContractTrigger: line 6, column 1
@isTest
public Class TestUpdateCharge {
static testMethod void testChargeContractTrigger(){
Charge__c c = new Charge__c (Monthly_Recurring_Charge__c = 111.00);
insert c; <-- line 6
c = [select id,contract__c,Opportunity__c from Charge__c where Monthly_Recurring_Charge__c = 111.00];
System.assertEquals(null, c.contract__c);
System.assertEquals(null, c.Opportunity__c);
}
}
Thanks again
Again, as the exception message states, there is a missing field missing. I expect your Charge__c custom object has a required lookup to an Opportunity record. You'll have to make one in your test method, insert it and assign a reference to the relation field in your Charge__c record before you insert that.