function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Julio HernandezJulio Hernandez 

Create Log a Call with Apex


I created an apex class that creates a task. Im wondering how I can change that to 'Log a Call'. The reason I want to do this is because in our feed view in cases there is a 'Log a Call' section and a 'Task and Activity' section. I want to populate the Log section rather than the Task section. 

-Julio Hernandez
SonamSonam (Salesforce Developers) 
Hi Julio,

I tried the below code to create a call log using apex trigger and it seems to be working.The call gets logged under the activity log as a call after the contact is created.

Please check the fields I have selected to make the task register as a call, list of Task fields given here:


trigger logcall on Contact (after insert) {
      //create a task for the new contact
                //Task newTask = new Task(Subject='Complete Survey for Transaction');
                Task newTask = new Task(Description = 'Survey Transaction',
                                        Priority = 'Normal', 
                                        Status = 'Completed', 
                                        CallDisposition = 'Call back',
                                        Subject = 'Call',  // setting this makes this task registered as a call
                                        CallType = 'Outbound',
                                        IsReminderSet = true, 
                                        ReminderDateTime =, 
                                        WhoId =[0].Id    );             
                insert newTask;
Ramesh Peetha 4Ramesh Peetha 4
Mandatory fields to create a task as call log are
CallObject //should be unique
Type='Call' // should be of type Call

Not sure but usuallty 
Status = 'Completed' // in call logs

Try following code from anynomous block
insert (new Task(Description = 'task for call log strictly',
                                        Priority = 'Normal', 
                                        Status = 'Completed', 
                                        Subject = 'Ramesh Test time 2',
                                        CallObject = 'shfusahfj-fdsbfh-fsdbhafb',// should be uniques
                                        CallType = 'Outbound',

Om PrakashOm Prakash
Just you need to use TaskSubtype = 'Call' while creating Task object  from apex code.