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
shra1_devshra1_dev 

REG: Problem in retireving the parent Id in Javascript on Detail Page Button

Hi,

 

I have created a Detail Page Button Child__c object. For that I was using an Onclick javascript.

 

In that javascript I have given:

 

var ParentId = "{!Child__c.Parent__c}"; //where Parent__c is the lookup to the Parent__c object

alert(ParentId);

 

Alert prints the Parent Record "Name" where I was expecting the "ID". Why it is taking the Name? How to retrieve the Id without querying the object?

 

Please help me...

 

Regards,

Shravan

Best Answer chosen by Admin (Salesforce Developers) 
Rahul SharmaRahul Sharma

Check this:

 

var ParentId = "{!Child__c.ParentId__c}"; //where Parent__c is the lookup to the Parent__c object

alert(ParentId);

 

All Answers

Rahul SharmaRahul Sharma

Check this:

 

var ParentId = "{!Child__c.ParentId__c}"; //where Parent__c is the lookup to the Parent__c object

alert(ParentId);

 

This was selected as the best answer
shra1_devshra1_dev

Thanks Rahul.. It has worked...

 

 

But what happens if I have ParentId__c(of type text suppose) also as a field in the Child__c object? Then how to retrieve the ParentId__c field

 

 

Regards,

Shravan

Rahul SharmaRahul Sharma

Hi Shravan,

Glad to know its resolved..

If you have a Text field with same name, Still it will show give the Id of Lookup Field instead of the value of Text field.

That means Id will overide the Text Field!