Creating Activity on insertion of record using trigger in Salesforce

Creating Activity on insertion of record using trigger in Salesforce

Add the Activity related lists:




Sample Trigger:


trigger EmployeeActivityTrigger on Employee__c (after insert) {
    List<Task> listTask = new List<Task>();
    for(Employee__c emp : trigger.new) {
        Task tk = new Task();
        tk.WhatId = emp.Id;
        tk.Description = ‘Conact the employee’;
        tk.Subject = ‘Employee Created on ‘ + Date.today();
        listTask.add(tk);
    }
    insert listTask;
}

Output:



Leave a Reply