Activity Forums Salesforce® Discussions Trigger to assign a task to the users in the public group whenever a Case is created or updated

  • Trigger to assign a task to the users in the public group whenever a Case is created or updated

    Posted by Ragavendra on September 14, 2018 at 5:28 PM

    Can anyone please help to solve the below scenario.
    I am having a Case object with two picklist fields

    • Reason
    • Secondary reason
      The above picklist fields contains many values. I am focusing on whenver a Case is created or updated with Reason value as Test_Reason & Seconday Reason value as Test_Secondary_Reason, I would be assigning the created task by fetching the two fixed users(A & B) stored in a public group(Group name: Test_PG).
    • This discussion was modified 7 years, 9 months ago by  Ragavendra.
    shariq replied 7 years, 9 months ago 2 Members · 3 Replies
  • 3 Replies
  • shariq

    Member
    September 17, 2018 at 10:35 AM

    Hi,

    From what I Understand from your requirement, you need to assign task to a group of fixed two users on created/updated case( picklist values).

    Try this –

    trigger CaseTaskAssign on Case (after insert, after update) {
    List<Group> grpToAssign = [SELECT Id FROM Group where Name = ‘Test_Pg’ LIMIT 1];
    List<Task> listTask = new List<Task>();
    for(Case newCase : Trigger.new){
    if(newCase.Reason__c == ‘Test_Reason’ && newCase.Secondary_reason__c == ‘Test_Secondary_Reason’){
    Task task = new Task();
    task.OwnerId = grpToAssign.get(0).Id;
    task.Subject=’Donni’;//Dummy
    task.Status=’Not Started’;//Testing value
    task.Priority=’Normal’;//Testing value
    }
    }
    if(listTask.size() > 0){
    insert listTask;
    }
    }

     

    Hope this helps.

  • [adinserter block='9']
  • Ragavendra

    Member
    September 17, 2018 at 11:03 AM

    Hi Sahriq,

    Thanks for your coding. I have a doubt in the part where you are assigning the task ID to group ID by mentioning the Indices-Zeroth element in the list. But how i could i able to assign to the two users in that list?

  • shariq

    Member
    September 17, 2018 at 11:06 AM

    Hi,

    Actually I am assigning a group of two users to the Owner of the Task. Could you please provide more detail what you want.

    Thanks for your reply.

Log In to reply.