Tuesday, 14 September 2021

How to get Salesforce lookup field object id using javascript ?

 When we  add a look input field then salesforce add a hidden field to capture Id. We need to get value from hidden field to get record Id.

For example 

<apex:inputfield value="{!Custom__c.lookField__c}"  id="lookupfieldId" />

<script type="text/javascript">

function getLookupId()

{

var fieldId = document.getElementById('{!$Component.lookupfieldId}_lkid').value;

alert('id'+fieldId );

}

</script>

We can also inspect field to get Id use it 

var fieldId =  document.getElementById('{!$Component.pageId:formId:pgBlkId:pgBlkSecId1:lookupfieldId}_lkid').value;

No comments: