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
prasanth kumarprasanth kumar 

dml exception in test class.

System.DmlException: Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, Assigned To ID: owner cannot be blank: [OwnerId] 

Class.eventtestclass.testingeventtrigger: line 17, column 1
 
@istest
public class eventtestclass {

    @istest static void testingeventtrigger()
    {
        opportunity op1=new opportunity();
        op1.name='testingopp1';
        op1.StageName='closed won';
        op1.closedate=date.parse('12/12/2016');
         insert op1;
        
     Event e11 = new Event(whatID = op1.ID, Ownerid = op1.ownerid);
        	e11.ActivityDate=date.today();
        	e11.subject='hello';
	        e11.StartDateTime = Op1.closedate;
	        e11.EndDateTime = Op1.closedate;   
	        insert e11;
        
        opportunity opp=[select id,name,nextstep,description from opportunity limit 1];
        
        string name1=e11.subject + ' ,' + e11.ActivityDate;
        system.assertequals(opp.NextStep,name1);
        
    }
    
}

 
AshlekhAshlekh
Hi,

 
@istest
public class eventtestclass {

    @istest static void testingeventtrigger()
    {
        opportunity op1=new opportunity();
        op1.name='testingopp1';
        op1.StageName='closed won';
        op1.closedate=date.parse('12/12/2016');
        insert op1;
      
     op1 = [select closedate,id, ownerid from opportunity where id =:op1.id];


     Event e11 = new Event(whatID = op1.ID, Ownerid = op1.ownerid);
        	e11.ActivityDate=date.today();
        	e11.subject='hello';
	        e11.StartDateTime = Op1.closedate;
	        e11.EndDateTime = Op1.closedate;   
	        insert e11;
        
      
        
        string name1=e11.subject + ' ,' + e11.ActivityDate;
        system.assertequals(opp.NextStep,name1);
        
    }
    
}

Hope this will help you.

-Thanks
Ashlekh Gera