title: Create Task from button on Custom Object Listview
body: <p>I have requirement where I have to create a button on custom object's <strong>list view</strong> , when clicked on that button a task should be created and assigned to a profile name HR.</p>
  <p>Behavior of 'Execute Javascript', and content source of 'OnClick Javascript'</p>
  <pre><code>{!REQUIRESCRIPT(&quot;/soap/ajax/31.0/connection.js&quot;)}
  
  try{
  var taskToCreate = new sforce.SObject(&quot;Task&quot;);
  
  taskToCreate.OwnerId = &quot;{!$User.Id}&quot;;
  taskToCreate.WhatId = &quot;{!Wage_Register__c}&quot;;
  taskToCreate.Subject = &quot;Hr Approval&quot;;
  taskToCreate.ActivityDate = new Date();
  
  taskToCreate.Priority = &quot;Normal&quot;;
  taskToCreate.Status = &quot;Completed&quot;;
  
  
  
  result = sforce.connection.create([taskToCreate]);
  
  if(result[0].success == &quot;true&quot;){
  location.reload();
  }
  else{
  alert(
  &quot;An Error has Occurred. Error: \r\n&quot; +
  result[0].errors.message
  );
  }
  }
  catch(e){
  alert(
  &quot;An Un-expected Error has Occurred. Error: \r\n&quot; +
  e
  );
  }
  </code></pre>