function readOnly(count){ }
Don't have an account?
Search for an answer or ask a question of the zone or Customer Support.
You need to sign in to do that
Sign in to start searching questions
Signup for a Developer Edition
Sign in to start a discussion
trigger autoCreateTask on Case (after insert, after update) { List<Task> insertTask = new List<Task>(); for(Case newCase : Trigger.new) { Task newTask = new Task(); newTask.subject = 'Automated Task'; newTask.whatId = newCase.Id; newTask.ownerId = newCase.OwnerId; newTask.status = 'In progress'; newTask.Priority = 'Normal'; insertTask.add(newTask); } if(insertTask.size() > 0) insert insertTask; }
You can create a task in two ways using Workflow and Apex trigger. Use the following code it will be working as you expected.
Here is the sample code for trigger which will create a new Task when a new event is created on account/opportunity.
trigger createnewTask on Event (after insert){
List<Task> tasks = new List<Task>();
List<Event> ev = Trigger.new;
for (Event evv : ev) {
Task tsk = new Task(Ownerid = evv.OwnerId, Subject=evv.Subject, whatid=evv.whatid); //pass values to new task (use whoid=evv.whoid in case of contact)
tasks.add(tsk); //add task to record
}
insert tasks;
}
Can you try and replace "EVENT" with case?
Best Regards
Naga kiran