I am developing an internal site for all company employees (basically an intranet). I am using a visualforce page but it must be externally available because not all company employees have a Salesforce license. One of the pages will be used for an internal competition.
I have a requirement to display a lookup field to a custom object. When typing in the lookup field and submitting the record, an invalid ID is passed to my controller. I'm assuming it's invalid because the field does not populate when the record is saved. When I grab the ID from the debug log and add it to my URL 'https://myinstance.salesforce.com/MyIDFromDebugLog' I get an Insufficient Privileges error.
When I click the lookup icon, and select the name of the record, I get a valid ID and the field is populated when the record saves.
How come when the user types a name in a lookup field on a force.com site, the ID is incorrect; however, when the user selects the record name from the lookup icon the ID is correct?
My Code:
<apex:inputfield value="{!Lead.my_field__c}" id="myField" onchange="javascript:getField('{!$Component.lc}_lkid')"/>
function getField(field) {
f = document.getElementById(field).value;
}
I suspect it has something to do with the onchange event in my input field.
Update
I found a great article by @Daniel Ballinger that explains the invalid ID. The invalid ID in my debug log('000000000000000AAA') is the empty key for relationships where there is no target record.
Is there a way to force the lookup field to search for the record once the user has entered a string?