I'm trying to override the standard log a call functionality but with some changes. When creating a log a call record it will be possible to select multiple users and multiple contacts. I've created the page with a possibility to select multiple contacts and multiple Users. But now i'm stuck with trigger.
After the user selected multiple users the id's of selected populates in a field UserListField__c
(The values are devines with ,
), the same is with ContactListField__c
. I don't really know how to fire trigger to create multiple records based on UserListField__c
.
This is what i've done for now:
trigger MultiTaskCreate on Task(before insert) {
//Trying to Make the List of Users Id's instead of string
List < String > UsrId = new List < String > ();
for (Task task: trigger.new) {
UsrId.add(task.UserListField__c);
}
//Creating new Tasks records
for (Task ts: trigger.new) {
If(UsrId != NULL) {
Task task = new Task();
task.Assigned_To__c = UsrId; //Using the Lists of Id's
task.Status = 'Completed';
task.Priority = ts.Priority;
task.Communication_Type__c = ts.Communication_Type__c;
task.Subject = ts.Subject;
task.Name__c = ts.Name__c;
insert task;
}
}
}