function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Will_LWill_L 

Retrieving an Object ID from a custom lookup field

Hi,
I am working on creating a custom web page that is basically a poor mans Mail Merge.  Basically we have a custom object that has all of the information I need in it, but I can use the normal mail merge to get everything we need in the print out.  So instead my thought is to just make a web page and some javascript and then just print that out instead.
 
The issue I am running into is the custom lookups we have.
In my example, I have the account linked to the my new Custom object (CustomObject), but additionally I have 2 different contacts linked to the object that may or may not be linked to the main account.  Contact one is say a Bill To contact and Contact 2 is the Ship To contact.  The web page that I want to create needs to go and get details on the 2 different contacts.
The code:
{!CustomObject__c.Bill_to_Contact__c} gets me the name of contact 1
{!CustomObject__c.Ship_to_Contact__c} gets me the name of contact 2
The issue is that my JavaScript needs the IDs of these 2 contacts so I can query the records.  I have no idea how to go and get these from my custom object.  Bill_to_Contact__c and Ship_to_Contact__c are lookup fields.
 
I'm attempting to write this in JavaScript as I have not done much investigating into VisualForce yet. If anyone can lend me any help on this I would be greatly appreaciative.
 
Thanks
werewolfwerewolf
As Obi-Wan Kenobi says: Use the force, Luke.

In other words, write a SOQL query to get your custom object using the Ajax Toolkit.
sfdcfoxsfdcfox
Adding "Id" to the field name returns the ID of the record, instead of the "name". For example:

{!Opportunity.Bill_To__c} = "Marc Benioff's Laptop"
{!Opportunity.Bill_ToId__c} = "006300000000aZ851"
Ankit Gupta 305Ankit Gupta 305
Thankew so much @sfdcfox, it worked what i exactly wanted.