I'm replicating the "New Task" page, with "Log Activity" branding instead of "Log a Call" & removing the extra "Follow-up Task" section.
As part of the standard behavior, the polymorphic
WhoId field is included. When the type of this field is changed to "Prospect", from "Contact", the
WhatId field is disabled.
It looks like this behavior is included on the visualforce page, but whenever I change the type, this error shows up in the log:
Uncaught DOMException: Failed to execute 'querySelector' on 'Document': '[secid=j_id0:j_id2:j_id3:j_id5:WhoId_mlbtn]' is not a valid selector. at Function.LookupAutoCompleteInputElement.handleLookupTypeChange (https://c.cs14.visual.force.com/jslibrary/1521492146000/sfdc/main.js:1888:12) at HTMLSelectElement.onchange (https://c.cs14.visual.force.com/apex/NewTask?who_id=00Qc000000AM49a&core.apexpages.request.devconsole=1:114:1648) LookupAutoCompleteInputElement.handleLookupTypeChange @ main.js:formatted:30259 onchange @ NewTask?who_id=00Qc000000AM49a&core.apexpages.request.devconsole=1:114
[secid=j_id0:j_id2:j_id3:j_id5:WhoId_mlbtn] seems to be the bit thats failing to execute properly. Problem is, this is standard code, out of my reach. I tried adding my own event listener, but it fails to run, probably since this one fails first.
document.getElementById('j_id0:j_id2:j_id3:j_id5:WhoId_mlbtn'); gets me the element I need, but trying to use a query selector fails. According to the
: is a non-standard css id value (which infuritates me that salesforce used a character that doesn't work out of the box with the spec), meaning it needs to be escaped (
//:) in order to work properly. This requires me to modify the
onchange attribute, which feels super brittle.
Looking at the standard page, the
onchange functions look like this:
The Id in this context is
'tsk2', which does not contain invalid characters, and is fetchable using
I also tried using
html-id to override the provided id, but this is explicitly disallowed.
Are there any other solutions? Has anyone else encounter this before?