When I create and assign a task programmatically to a user, the notification does not show up in the Universal Notification Service (UNS) bell for the target user.
Below the code to execute anonymous to test it. It is important to assign the task to a different user that the one that is creating the task.
Task task = new Task(); task.OwnerId = <userId parameter>; task.Priority = 'High'; task.subject = 'Task test'; insert task;
It works it the task is created by UI: