Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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.

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

2 Answers 2

up vote 2 down vote accepted

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.

share|improve this answer
1  
Strange error message then. Normally it would show you a message like "A mandatory field is null" or something else... –  mast0r Dec 17 '12 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 Dec 17 '12 at 21:19
  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.
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.