How to create Task using Apex in Salesforce?

Sample Code:

    Task T = new Task();
    T.Type = 'Email';
    T.Description = ''; //string
    T.OwnerId = ''; //user id
    T.WhatId = ''; //record id
     insert T;


Cheers!!!

2 comments:

  1. HI, can you tell me how to assign a single task to a particular ROLE having multiple users.
    Coz i have tried T.OwnerId=' role id'; but this is not working.
    can you help me here?

    ReplyDelete
    Replies
    1. Use the below link

      http://www.infallibletechie.com/2014/11/how-to-query-user-information-from-role.html

      Create list of tasks with OwnderId from the above.

      Cheers!!!

      Delete