This does set up a new heading in the target file, however the new heading is not assigned an id. Instead, the file itself is given an id (if it does not have one already).
I would like instead for the new heading to be given an id and for the link to refer to the heading (instead of the file).
I had a quick look at the current code. It does not look to be designed to work in the way you would like. The headline node is not created in time to be passed to the capture finalize function, which inserts a new ID link.
I could suggest two options:
Code it yourself (with others’ help – I can’t see how this can be done easily)
Create a project’s GitHub issue to request a new feature
This is only as far as I could see. Other people might have better ideas.
I set up the following to capture with the standard org-capture and the org-capture templates. The key is to create an ID automatically in the capture buffer with the hook: :hook (org-capture-mode . org-id-get-create). I could not get it to work with org-roam-capture as it seems to use the ID of the file as mentioned above.
(defun nom/org-roam-capture-create-id ()
"Create id for captured note and add it to org-roam-capture-template."
(when (and (not org-note-abort)
(org-roam-capture-p))
(org-roam-capture--put :id (org-id-get-create))))
(add-hook 'org-capture-prepare-finalize-hook 'nom/org-roam-capture-create-id))