Can I run following code after login as customer portal user in apex controller?

task.WhatId = Object.id;
task.WhoId = Object.Editor__c;
task.Subject = 'Other';
task.priority= Object.Priority__c;
task.status = 'Not Started';
task.description = 'New  Work';
insert task;

I am getting error "Currently DML is not allowed". I want to create a task for customer portal user. Is that possible? I don't want show it to any user. I will just use it to send notification email. Is there any way to do so?


Well seems like you are doing DML from either Constructor or Getter method. Please try to do the same from action attribute of the page by calling a method

  • I am calling an action method from VF page and action method calls this code. Please note context user is customer portal user. – doga Feb 28 '13 at 3:47

There's a blog post about this from Wes Nolte that even contains a short poem:


This covers all of the scenarios and solutions for each of them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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