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
MohanaGopalMohanaGopal 

Accessing Parent Fields from Related list Visual force page

Hi..
      I have create one custom list button in  my custom object (A)  as VF page.. This object is related to master detail look up to another custom object (B)....
      That is  A is child B is Parent... 
 When I click my custom list button  from related list of Parent object (B) I have to access parent object fields...
 
How is it possible...
 
I try following code for passing parent id to VF page in onclick  of java script for calling this VF page.. It doesnt work properly...
That is parent id goes blank to the url
 
window.location.href = '/apex/myvfpagename?id={!A__c.B__c}';
 
Any one give some sample code for accessing parent fields or passing parent id to VF page....
hisrinuhisrinu
Hi,

If you are using master detail lookup, you will get the parent record id in the child itself right?
with that record id you can easily fetch the values.
If you want more clarification just mention the objects names and then how you are giving the relationship between those two objects.

MohanaGopalMohanaGopal
Hi..
 
Its create new records..
My Code is
 
<apex:page standardcontroller="CalculatedMeasures__c" extensions="Control1">
<apex:form >
<apex:pageBlock title="Calculated Measure Edit" mode="edit">
  <apex:pageBlockButtons >
    <apex:commandButton action="{!save}" value="Save"/>
    <apex:commandButton action="{!save}" value="Cancel"/>
  </apex:pageBlockButtons>
 
  <apex:pageBlockSection title="Information" id="info">
    <apex:inputField id="CurrentProject" value="{!Calculated_Measures__c.Project__c}"/>
  </apex:pageBlockSection>
 
.....
 
Here Calculated_Measures-child object
Project__c -Parent object
 
When I click my custom list button I saw blank value in Current project input field (Samething happened I ovverride New buuton)
 
 I want to get parent id.. Based on this id I have to do some calcultion and accessing parent fields in this page...
 
How to get parent id.....
 
Please send some sample code for it...
 
(I think when I click the custom list button that only child records going to create, So child record is not created when I click this button. we cant access null record . parent id .. How to get parent id)
 
 
MohanaGopalMohanaGopal

Hi,,

I have override child new button as VF page, When I click new button in Parent Related list I need to didplay  parent name in corresponding field in Child page.. I have to fetch values based on the parent id from another object.. But my case Parent Id is null .. Can u send sample code for getting parent id..
My code is
  <apex:pageBlockSection title="Information" id="info">
    <apex:inputField id="CurrentProject" value="{!Calculated_Measures__c.Project__c}"/>
  </apex:pageBlockSection>

Any one send sample code for resolve my problem..

 

jeffersonjefferson
... Seven years later

Does anyone have an answer to this? I've got the exact same issue. Thanks.
Prasad KairamkondaPrasad Kairamkonda
+1
Khanh Pham-KlomosKhanh Pham-Klomos
Hi guys,

I just came across very similar requirement as MohanaGopal.
What I've done might be a bit handy and specific but at least I can achieve my goal: having parent Id so that I can do other things in my visualforce page.

What I did is to use JavaScript to do some parsing for the custom button in child object. Details as below

{!REQUIRESCRIPT('/soap/ajax/20.0/connection.js')} 
{!REQUIRESCRIPT('/soap/ajax/20.0/apex.js')} 

var currentLocation = location.href;
var lastSlashIndex = currentLocation.lastIndexOf("/");
var parentId = currentLocation.substring(lastSlashIndex + 1, currentLocation.length);

location.href= '/apex/page_SetupContainerInfo?parentId=' + parentId;

Hope that help.