The task for the custom action is defined as compound tasks. For example, helloworlds.custom

Step 1: View File

You can add the custom toolbar button in the view file as follows:

JToolbarHelper::custom('helloworlds.custom', 'ok', 'ok', 'Custom Button', false);

Now, Joomla will look for the custom() function in the subcontroller file: admin/controllers/helloworlds.php

Step 2: Subcontroller File

You can extend the class with JControllerLegacy, JControllerAdmin or JControllerForm. For example,

class <component_name>Controller<subcontroller_name> extends JControllerForm
{

}

Next, define the custom() function. This function gets the data or information from either the GET request or POST request or both. Then, it gets the model and passes the data to the required function of the model. Then, it sets a message and finally sets a redirect.

public function custom()
{
$input = JFactory::getApplication()->input;

$id = $input->get('id', '0', 'INT');
$recs = $input->get('cid', 'array()', 'ARRAY');
$nrecs =  $input->get('boxchecked', '0', 'INT');

$model = $this->getModel('custom', 'HelloWorldModel');
$model->custom($recs);

$this->setMessage('Message.');
$this->setRedirect(JRoute::_('index.php?option=com_helloworld&view=helloworlds', false));
}

The getModel() function is defined in the JControllerLegacy class. Its arguments are name and prefix.

Step 3: Model File

The model performs any required operations on the data. Here, you can use JTable for handling database queries.

You can extend the model class with JModelLegacy, JModelForm, JModelAdmin, JModelList or JModelItem.

public function custom($recs)
{
$table = $this->getTable('HelloWorld', 'HelloWorldTable');

foreach($recs as $id)
{
$table->delete($id);
}
}

The getTable() function is defined in the JModelLegacy class. Its arguments are name and prefix.