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
ArmanMArmanM 

Get related object info

H,

I have a object called Media_Deliverable__c that has master detail relationship with Media_Plan__c.

In Media_Plan__c I have a button that renders as PDF. I need to get information from its related list items from Media_Deliverable into this PDF as well. How can I do this?

Thanks,
Arman 
Best Answer chosen by ArmanM
Manohar kumarManohar kumar

Hi Arman,

Code will look like this.

public with sharing class Abc {
    public List<Media_Deliverable__c > childLs{get;set;}
    
    public Abc(ApexPages.StandardController controller) {
        
        childLs= List<Media_Deliverable__c >();
        id parId = ApexPages.currentPage().getParameters().get('id');

      childLs = [select id, Fields from Media_Deliverable__c  where Media_Plan__r = :parId ];


        
    }

 

put the constructor code in your controller. And use childLs to display for records.

Please let me know if this works.

Thanks,

Manohar

All Answers

Manohar kumarManohar kumar

Hi Arman,

Make a visual force page that renders as a pdf and in the controller get the id of the current page. Then query the realted list and display.

Please let me know if this hepls.

Thanks,

Manohar

ArmanMArmanM
Thanks Manohar, I get what you mean. Could you please provide a little more information as to what this controller would look like because I already have a page that is rendering as a pdf at the moment. I just need to get information from each line item of its child object. 
Manohar kumarManohar kumar

Hi Arman,

Code will look like this.

public with sharing class Abc {
    public List<Media_Deliverable__c > childLs{get;set;}
    
    public Abc(ApexPages.StandardController controller) {
        
        childLs= List<Media_Deliverable__c >();
        id parId = ApexPages.currentPage().getParameters().get('id');

      childLs = [select id, Fields from Media_Deliverable__c  where Media_Plan__r = :parId ];


        
    }

 

put the constructor code in your controller. And use childLs to display for records.

Please let me know if this works.

Thanks,

Manohar

This was selected as the best answer
ArmanMArmanM
Thank you for providing the example, I modified it a little bit to include more fields that I would need.
public with sharing class Abc {
    public List<Media_Deliverable__c > childLs{get;set;}
    
    public Abc(ApexPages.StandardController controller) {
        
        childLs= List<Media_Deliverable__c >();
        id parId = ApexPages.currentPage().getParameters().get('id');

      	childLs = [select id, Deliverable_Name__c, Product__c, Product_copy__c, 
		Quantity__c, Rate__c, True_Total_Value__c, Value__c, Value_Add__c,
		Value_add_price__c from Media_Deliverable__c where Media_Plan__r = :parId ];
    }
}

After doing so, I am getting 'unexpected token: 'List'' error in line 6. Not sure why this is happening? 
Manohar kumarManohar kumar

My bad, forgot to put new.

 childLs= new List<Media_Deliverable__c >();

pls try this.

ArmanMArmanM
I am now getting "No such column 'Media_Plan__r' on entity 'Media_Deliverable__c'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names." 

In this master-detail relationship:
Media_Plan__c is the parent/master 
Media_Deliverable__c is the child/detail 

Should I change Media_Plan__r to Media_Plan__c? 
Manohar kumarManohar kumar

yes try...