You need to sign in to do that
Don't have an account?
Robert Bange*
Cannot insert an Event with a test class
I have created a test class for testing a trigger on Event.
I get the the error:
Class.testTriggerOnEvent.insertEvent: line 19, column 1
Line 19 is the insert -
I would welcome suggestions to make this work...
Regards, Robert
This is the class:
@istest
public class testTriggerOnEvent {
static testmethod void insertEvent() {
Event e = new Event();
e.Subject='Test for trigger';
e.WhatId='001g000000Msxb7AAB';
e.WhoId='003g000000JkXolAAF';
e.OwnerId='00520000003bZVYAA2';
e.recordtypeid='012g00000000VSrAAM';
e.Type='Visit';
e.IsAllDayEvent=false;
e.DurationInMinutes=60;
e.activitydatetime=system.now();
e.ShowAs = 'Busy';
e.IsReminderSet = false;
insert e;
}
}
I get the the error:
Class.testTriggerOnEvent.insertEvent: line 19, column 1
Line 19 is the insert -
I would welcome suggestions to make this work...
Regards, Robert
This is the class:
@istest
public class testTriggerOnEvent {
static testmethod void insertEvent() {
Event e = new Event();
e.Subject='Test for trigger';
e.WhatId='001g000000Msxb7AAB';
e.WhoId='003g000000JkXolAAF';
e.OwnerId='00520000003bZVYAA2';
e.recordtypeid='012g00000000VSrAAM';
e.Type='Visit';
e.IsAllDayEvent=false;
e.DurationInMinutes=60;
e.activitydatetime=system.now();
e.ShowAs = 'Busy';
e.IsReminderSet = false;
insert e;
}
}
All Answers
You should also create a User records for the WhoId and OwnerId as well.
Additionally, the RecordTypeId is likely to change between Sandbox / Production at somepoint, so I would suggest querying for the RecordType by its developer name instead of hardcoding the RecordTypeId.
Hope that helps.