You need to sign in to do that
Don't have an account?
megsuma
Apex Trigger Not Respecting testMethod Code
Hi all, once again Apex has left me scratching my head. I have a trigger that I'm trying to test, here is my test method for that trigger:
static testMethod void testCompanyGoalUpdate(){ Company_Goal__c cmp = new Company_Goal__c(); Company__c myCompany = new Company__c(); cmp.Test__c = 'Test'; cmp.Company__c = myCompany.Id; System.debug(cmp); insert cmp; delete cmp; }
Eclipse tells me:
System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Company__c]: [Company__c]
In the snippet above I was sure I set Company__c properly with "cmp.Company__C = ..."
I am definitely open to suggestions, I'm not even sure I'm writing the test method quite right as this is my first test method for a trigger (after insert, after update).
System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Company__c]: [Company__c]
here the problem is there is some validation rule hitting while u r trying to insert.check if u r missing something or else check ur company is having some recordtypes u need to mention that tooo while u r creating a test company.
the test methhod u have written is little bit confusing.
any test method u need to create a test account and insert it and then do some operation on testa ccount and insert again.
for wxample.
sorry small change in above script
The problem is that myCompany is never inserted, so myCompany.id is null. You need to "insert myCompany" before adding its ID to cmp.Company__c.
Jeremy