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
Ritesh__Ritesh__ 

first error: INVALID_CROSS_REFERENCE_KEY, Assigned To ID: owner cannot be blank: [OwnerId]

i am writing a test for my controller for that i have to insert event in test database my test method is

static TestMethod void Test1_TestInsertWithValue()
{Meeting_Master__c master=new Meeting_Master__c();
Event event =new Event();
Profile p=[SELECT Id From Profile WHERE Name='Standard User'];
User u2 =new User(Alias = 'newUser' , Email ='newuser@testorg.com' , EmailEncodingKey = 'UTF-8' , LastName = 'Testing',
LanguageLocaleKey='en_US',LocaleSidKey='America/Los_Angeles', UserName='newuser@testorg.com',ProfileId=p.Id);

event.OwnerId =u2.Id;
event.StartDateTime =datetime.newInstance(2008, 12, 1);
event.EndDateTime = datetime.newInstance(2008,12,30);
event.subject='call';
event.WhatId=master.Id;
insert master;
insert event;
...........
}

when insert event occur i am facing error System.DmlException: Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, Assigned To ID: owner cannot be blank: [OwnerId]

how to rectify this error??

Best Answer chosen by Admin (Salesforce Developers) 
klekle

Hi there, you didn't insert the User.  Add
   insert  u2;

at the end of the block where you are adding its properties.

 

Please post back and let me know if this was it!

 

-Kemi

All Answers

klekle

Hi there, you didn't insert the User.  Add
   insert  u2;

at the end of the block where you are adding its properties.

 

Please post back and let me know if this was it!

 

-Kemi

This was selected as the best answer
salesforce@14salesforce@14
Hi all,

          I am trying to get owner id of parent object. but i am not able to get it.
I did like this .

ParentObject__r.OwnerId

can any one tell me how to resolve it..

thanks.