Hello and thanks in advance for any help!
I have a VF page with 2 lookup inputFields and a picklist (built as an inputField with dynamically-populated picklist choices). There is an actionsupport with event="onchange" attribute on the picklist. When the "WorkOrder.Job_Type__c" picklist changes, the "Account__c" lookup inputField is populated by the controller (via SOQL), and then the second, "Installer Contact" lookup inputField is populated by a SOQL query using information from the Account__c record.
<apex:inputField value="{!WorkOrder.Job_Type__c}">
<apex:actionSupport event="onchange" action="{!updateInstaller}" rerender="installer, installerContact" />
</apex:inputField>
<apex:inputField value="{!WorkOrder.Account__c}" id="installer">
<apex:actionSupport event="onchange" action="{!updateInstallerContact}" rerender="installerContact" />
</apex:inputField>
<apex:inputField value="{!WorkOrder.Installer_Contact__c}" id="installerContact" >
</apex:inputField>
I've hit a bug in the following situation:
- When the Account__c inputField is populated by the controller, and the Installer_Contact__c inputField is subsequently populated by the controller as well, and then:
- I change the Job_Type__c picklist value, and if there happens to be more than one record with the same name as the current Installer_Contact__c record in the inputField, everything about the Installer_Contact__c inputField disappears except for the magnifying glass, and no error messages show up apart from in the debug logs (message is "VF_PAGE_MESSAGE | Multiple items found, etc.")
Job_Type__c's actionSupport onchange action is never called in this case.
The specific Installer_Contact__c record retrieved by the controller's SOQL query is not being recognized; only the name is being read (as a String or text), causing the 'multiple items' error.
I am guessing that this is due to the controller populating the Installer_Contact__c inputField as a lookup (using the record Id), but when the picklist changes and the Installer_Contact__c inputField is being reevaluated right before Job_Type__c's actionSupport action is called, the input is seen as text type.
How can I get the inputField to recognize the specific Installer_Contact__c record that is already populating it, without the user having to click on the magnifying glass and choose a record?
Here is the code in the controller:
public PageReference updateInstaller() {
//if you're going from self install to non, change installer field to blank
if (!installerIsCustomer() && lastPickWasCustomerInstall) {
m_workorder.Account__c = null;
m_workorder.Installer_Contact__c = null;
//going from non to self-install, change installer to project account
} else if (installerIsCustomer() && !lastPickWasCustomerInstall) {
m_workorder.Account__c = m_site.Account__c;
updateInstallerContact();
}
return null;
}
public PageReference updateInstallerContact() {
//if self install and installer is the same as account owner, install contact is not custom
if (!installerContactIsCustom) {
Contact[] installerContacts = [SELECT Name, Id FROM Contact WHERE AccountId = :m_workorder.Account__c AND Owner__c = true LIMIT 1];
if (installerContacts.size() > 0) {
m_workorder.Installer_Contact__c = installerContacts[0].Id;
} else {
m_workorder.Installer_Contact__c = null;
}
}
return null;
}
Thanks for any help!!!