Greetings and thanks in Advance!
Have a visualforce page that allows a user to create a related lookup object.
<apex:inputField id="newCompetitorAccount" value="{!newCompetitor.Competitor_Account_Name__c}" />
<apex:inputText id="newCompetitorProximitiy" value="{!newCompetitor.Proximity__c}" />
<apex:commandButton reRender="newPanel, existingCompetitorPanel, pageMessages" value="Add" action="{!AddNewCompetitor}" status="updateStatus" id="NewSubmittalCompetitor" />
Note: the inputField newCompetitor.Competitor_Account_Name__c is a lookup to Account Object.
Want to populate this lookup based on another data source which only contains Names ( no account Ids).
Using the UI.. If a user types a MATCHING account name into the lookup box Salesforce magically associates this with correct Account. If the Account Name does not match then you get "Error: No Matches Found". If multiple Accounts are found you have the option to choose which Account.
My issues is I am trying to get this same behavior using Javascript to avoid having the user retyping the Account Name in the inputfield.
<a href="" onclick="setInputAccount('{!resultWrapper.result.name}', '{!resultWrapper.proximity}');" >Select</a>
function setInputAccount( accountName , proximity)
{
//alert(accountName);
$("input[name*='newCompetitorAccount']" ).val(accountName);
$("input[name*='newCompetitorProximitiy']" ).val(proximity);
$("input[name*='newCompetitorAccount']" ).onchange();
$("input[name*='NewSubmittalCompetitor']").click();
}
The issue is when javascript populates the inputfield and clicks the button you do not get the same behavior as a user would in the UI.
Instead you get this message "Error: value '{!newCompetitor.Competitor_Account_Name__c}' is not a valid id field"
Understand that the lookup wants the Account ID to be populated but do not understand why typing the name and clicking Add results in different behavior then doing this with Javascript. Would be perfectly fine with getting the standard error messaging but the error message displayed is cryptic to the users. This also doesn't display matching accounts if duplicates exists.
Have to be missing some event but cannot figure out what.
Any help!! Thank you!!