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
pacochin88pacochin88 

Need to access a Master object field from a Child controller in Visualpage

Hi,

 

I am new to SF development and I am trying to achieve below, hope someone can help.

 

Master object is "Product"

Child object is "Product_item"

 

I plan to create a VP page to generate pdf file, and create a custom button at the Product Item page, so that user can click a button to generate a pdf page to print.

 

Below is my code:

 

<apex:page renderAs="pdf" standardController="Product_Item__c">

 

//I want to display the Product.Product_name__c value here // 

// I dont know the syntax //

 

<apex:outputText value="{!Product_Item_Name__c}" styleClass="productName"/>

 

</apex:page>

 

 

Please help ! thks

SRKSRK

To solve your proble most ouick way is to use extenction


It means you have to write a apex class & use it in u page

 

 

 

 

public class YouNewApexClass

{

public Product_item ProductItemObj{get;set;}

public YouNewApexClass (ApexPages.StandardController stdController)

{

  ProductItemObj = [select id,name,ProductLookUpfiledname__c,ProductLookUpfiledname__r.name from ProductItemObj where id =: ApexPages.currentPage().getParameters().get('id')];

}

}

 

<apex:page renderAs="pdf" standardController="Product_Item__c" extenction="YouNewApexClass">

<apex:outputText value="{!ProductItemObj.ProductLookUpfiledname__r.name}"/> / this will show the related product name on page

</apex:page>

pacochinpacochin

Hi SRK,

 

Thank you for your reply.. Beside writing Apex class, is there any other way to work around ?

 

How about in Product_item object create a custom formula field called "Product Name" and use some look up function to populate this field based on the Master - Child relationship ?

 

I know this is not as elegant as writing Apex class, but i can live with it as I do not have resources and know how to write, test scripts.

 

Please advise

SRKSRK

Hi Yes you can use the formula field but in that case if you need any other detail from product you need to make that mush number of formula fields

 

u can use {!ProductlookUpfield__r.Name} t fatch the name on formual field & then can use the formula field on PDF

pacochinpacochin

Hi SRK,

 

Pardon me. I don't understand...are you saying, in my product_item object I can create a formula field (text) and insert 

 

{!Product__r.Product_Name__c} 

 

I tried, but I have an error saying Product__r doesn't exists.

 

When you say,  {!ProductlookUpfield__r.Name}, do you mean Productlookupfield is my Product object ?

 

thks

pacochinpacochin

Hi SRK,

 

I got it finally. I should use Product_Item__r.Product_Name__c in the new formula field  !!

 

thks so much !

SRKSRK

Grate

o my mistake i mention " {! } " Mager field sing  , In formula we do not need marge fields