0

In a test class I need to create an event object, and I want to assign the fields WhoId and WhatId. For now I wrote that in my test class:

Account c= new Account(FirstName = 'test',
                       LastName = 'test');                               
    insert c;
    Event ev = new Event(StartDateTime = DateTime.now(),
                         EndDateTime = DateTime.now(),
                         Subject = 'Appel',
                         WhoId = c.Id,
                         WhatId = c.Id);
    insert ev;

but when I run the test class, I got the error :

System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Name ID: incorrect type ID value;: 0017E00000BQTraQAH: [WhoId]

1 Answer 1

5

WhoId for an event has to be leadId or a contactId.

Create a contact record

  Contact cnt = new contact();
  Cnt.LastName = 'Test ';
  Insert cnt ;

Even.whoId = cnt.Id;

WhatId can be account,opportunity or custom object reference

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .