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
philanthropyphilanthropy 

not sure how to get the info needed with SOQL

So I'm still learning VF/apex and I've run into an issue. I have a master detail relationship, similar to an invoice with line items. I'm passing the ID of the invoice to a new VF page, using that ID I want to pull all all list item IDs associated with it and save them to a list. How would I write this? I keep trying different ideas but I'm having a hard time working out the steps. Any suggestions would be appreciated.

 

Update: I came up with this and it seems to be working? But now I can't get movieList to display on the VF page using either a dataTable or apex:repeat. Any ideas? I tried moving the code block to a get method for movieLIst and  that didn't seem to work either.

I was able to come up with this, it appears to be working but now I'm not sure how to display it on the VF page. It doesn't seem to work as a value for an apex:dataTable

public class SuccessController {

    public List<Unit_Rental__c> movieList {get;set;}
    public string moviePrice;
    string rentalRecordId;

   public SuccessController() {
       List<Unit_Rental__c> movieList = new List<Unit_Rental__c>();
       rentalRecordId=ApexPages.currentPage().getParameters().get('id');
       movieList=[SELECT ID, Movie__r.name FROM Unit_Rental__c WHERE Rental__r.ID=:rentalRecordId];
       System.debug(movieList[0].Movie__r.name);
   }

}

 

 

Thanks!

 

nandurinanduri

Try this :

 

 

public class SuccessController {
    public List<Child_Object__c> movieList {get;set;}

    public string moviePrice;

    string rentalRecordId;
    public SuccessController() {

        movieList = new List<Child_Object__c>();

        rentalRecordId=ApexPages.currentPage().getParameters().get('id');     

        movieList=[SELECT ID, Name FROM Child_Object__c WHERE Master_Field_on_Child__c=:rentalRecordId];                  

        System.debug('First Movie Name '+movieList[0].Name); 

     }
}

 

Now check your debug logs, hope this helps :)

Shashikant SharmaShashikant Sharma

Pleae share you VFP, will be helpful to trace out the issue.

philanthropyphilanthropy

Hm, I tried using your SOQL statement instead and it was returning the rental ID instead of the movie name. My debug is actually showing the correct result. I just don't know how to display the movieList on the VF page.

 

Here's my VF code its causing an error:

Error: Unknown property 'VisualforceArrayList.movie__r'

 

<apex:page controller="SuccessController">
  <h1>Congratulations you Rented a Movie Kinda!</h1>
  <br/><br/>  
  <apex:outputText value="Well {!$User.FirstName} here's what you just rented."/>
  <apex:repeat value="{!movieList}" var="movieList">
  <apex:outputText value=" Movie 1: {!movieList.movie__r.name}"/>
  </apex:repeat>   
</apex:page>

 

Will this not work? Is the apex:repeat only meant to iterate through an object not a list and I'm going about this the wrong way?

philanthropyphilanthropy

As an update I changed the var name to mv instead of movieList and it seems to be working now. Does anyone know why this is?

nandurinanduri

apex:repeat means, it iterates through a list. All you need to do is change the <apex:outputText value=" Movie 1: {!movieList.movie__r.name}"/> to

 

<apex:outputText value=" Movie 1: {!movieList.name}"/> and I think it should work