Hello Friends,
Recently I was working on a requirement where I have to validate some lookup field on visualforce page itself not in apex without submitting form to server.
I did lots of research and after having a lots of dig down of salesforce source code I identified each lookup field is associated with one hidden field with a "_lkid" appended to the id this help me to identify the record uniquely
<apex:page standardController="Contact">
<apex:form>
<apex:inputField value="{!Contact.AccountId}" id="accountId onchange="getAccountSFId();">
<script>
var accountId = "{!$Component.accountId}";
</script>
</apex:form>
<script>
function getAccountSFId(){
var accId = accountId + '_lkid';
// This will give you the 18 digit SF id of the account and you can do what ever you want with this
console.log(document.getElementById(accId ).value);
}
</script>
</apex:page>
Recently I was working on a requirement where I have to validate some lookup field on visualforce page itself not in apex without submitting form to server.
I did lots of research and after having a lots of dig down of salesforce source code I identified each lookup field is associated with one hidden field with a "_lkid" appended to the id this help me to identify the record uniquely
<apex:page standardController="Contact">
<apex:form>
<apex:inputField value="{!Contact.AccountId}" id="accountId onchange="getAccountSFId();">
<script>
var accountId = "{!$Component.accountId}";
</script>
</apex:form>
<script>
function getAccountSFId(){
var accId = accountId + '_lkid';
// This will give you the 18 digit SF id of the account and you can do what ever you want with this
console.log(document.getElementById(accId ).value);
}
</script>
</apex:page>