0

I'm trying to create a Task in Apex, but it doesn't seem to be working. Here's my actual code:

RecordType rt = [SELECT Id FROM RecordType WHERE Name = 'Some Record Type' AND SobjectType = 'Task'];
Task logCall = new Task(WhatId = friend.Id, RecordTypeId = rt.Id, Type = 'General Task', Subject = 'Here\'s my subject', Description = 'Description');

System.debug('@@@@@@@@@@@');

try {
    insert logCall;
} catch (DmlException e) {
    ApexPages.addMessages(e);
    return appendId(Page.SomeView);
}

When I execute that, there are no error returned to my view. When I check at the developer console, I get this error message:

15:35:28:208 VARIABLE_ASSIGNMENT [3]|this.message|"You do not have priv (40 more) ..."|0x67e122
15:35:28:208 VARIABLE_ASSIGNMENT [4]|this.message2|"You can not modify t (61 more) ..."|0x67e122

Any idea how to prevent that from happening?

Thanks.

3
  • Try to check your profile, it looks like you do not permissions on that object. Commented Dec 17, 2012 at 21:01
  • I have a System Administrator profile with every privilege enabled, so this is probably not the problem.
    – jpmonette
    Commented Dec 17, 2012 at 21:05
  • What is exactly You do not have priv... and You can not modify t? Commented Dec 17, 2012 at 21:13

2 Answers 2

3

It seems like the code is working. The reason I couldn't see it from my object Activity History is because I wasn't filling the DueDate and the Status.

So, a quick ActivityDate = Date.today() and Status = 'Completed' did the job.

2
  • 1
    Strange error message then. Normally it would show you a message like "A mandatory field is null" or something else... Commented Dec 17, 2012 at 21:14
  • I know, I don't get it. The main explanation I have right now is that the error might have been triggered by something else.
    – jpmonette
    Commented Dec 17, 2012 at 21:19
0
  1. Check the SysAdmin profile's allowed Task Record Types (this is enforced even if you're SysAdmin, on any object).
  2. Check if your "friend" object whatever it is that you're passing as WhatId) has "Allow Activities" ticked.
  3. Consider using normal Debug Logs or just open raw log so you can see the full message.

You must log in to answer this question.

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