I am getting the error like this on the test case can any body help me to reslove it
System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, quoteUpdateopportunity: execution of AfterInsert
caused by: System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: []
Trigger.quoteUpdateopportunity: line 10, column 1: []
This is my trigger wrote on quote
trigger quoteUpdateopportunity on quote__c( after insert) {
List<opportunity> oppToUpdate = new List<opportunity>();
for(quote__c quo : trigger.new){
if (quo.Quote_Number__c!= Null )
oppToUpdate.add(new opportunity(id= quo.Opportunity_Name__c, StageName = 'offer'));
}
if (oppToUpdate != null && !oppToUpdate.isEmpty())
update(oppToUpdate);
}
this is the test class i wrote
@isTest
private class quoteupdateopportunity{
static testMethod void testquoteupdateopportunity(){
quote__c qo=new quote__c(Author_Email_New__c='manoj.jena@kvpcorp.com');
insert qo;
opportunity op= new opportunity(name='test 002');
insert op;
op= [SELECT stageName FROM opportunity Where Id = :op.Id];
System.assertEquals ('offer',op.stagename);
}
}
Help me to find out get riid of this error
Best Answer
Updated your test class. you're inserting the quote object without adding any opportunity Id in the opportunity_name__c field which is causing the error message. I think instead of storing the id of the opporutniy in the quote object you should create a lookup relationship with opportunity
updated your trigger, i.e., if the opporutniy_name__c is null then do not enter the if condition.