You need to sign in to do that
Don't have an account?

Task creation for other User via trigger
Hi All,
I want to assign task to user, Not to lead/contact . Case Comment and Case has master details relationship.
trigger TaskForCaseCommentTrigger on Case_Comment__c (after insert)
{
List<Task> newTasks = new List<Task>();
//Loop through all records in the Trigger.new collection
//for(Case_Comment__c cc: Trigger.new)
for(integer i=0; i<trigger.new.size(); i++)
{
//List<Case> cases = [select id,Owner.Id from Contact where accountId = :a.Id];
system.debug('Owner ID----'+trigger.new[i].Case__r.OwnerId);
newTasks.add(new Task(
ActivityDate = Date.today(),
WhoID = trigger.new[i].Case__r.OwnerId,
Status = 'Not Started',
type = 'Other',
Priority = 'Normal',
Subject = 'Case Comment Added',
description = trigger.new[i].Comment__c
));
}
insert newTasks ;
}
I want to assign task to user, Not to lead/contact . Case Comment and Case has master details relationship.
trigger TaskForCaseCommentTrigger on Case_Comment__c (after insert)
{
List<Task> newTasks = new List<Task>();
//Loop through all records in the Trigger.new collection
//for(Case_Comment__c cc: Trigger.new)
for(integer i=0; i<trigger.new.size(); i++)
{
//List<Case> cases = [select id,Owner.Id from Contact where accountId = :a.Id];
system.debug('Owner ID----'+trigger.new[i].Case__r.OwnerId);
newTasks.add(new Task(
ActivityDate = Date.today(),
WhoID = trigger.new[i].Case__r.OwnerId,
Status = 'Not Started',
type = 'Other',
Priority = 'Normal',
Subject = 'Case Comment Added',
description = trigger.new[i].Comment__c
));
}
insert newTasks ;
}
I think you have to use Owner field of Task object.
and assign the user's id on that.
Reagards
Virendra