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 missing [Accountid]:Accountid]

I have a problem with Miising Field.  Here is full  test: -- 

 

 

private class TestChargeCostUpdate{
static testMethod void testCCUpdate(){
// create data
Account acc = new Account(name='TestAccount');
insert acc;
Opportunity op = new Opportunity(AccountId=acc.id,name='Test Opp',StageName='Provided Quote',CloseDate=Date.toDay());
insert op;
Charge__c es1 = new Charge__c(Opportunity__c = op.id, Monthly_Recurring_Charge__c=1);
insert es1;
Contract contr = new Contract(Opportunity__c = op.id);
insert contr;
   }

}

 

Error:

System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [AccountId]: [AccountId]

 

 

Thanks for your help. 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
fatmonkfatmonk

Never mind, I found it works

it is missing on contr

Contract contr = new Contract(Accountid=acc.id, Opportunity__c = op.id);