• philanthropy
  • NEWBIE
  • 25 Points
  • Member since 2011

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 12
    Replies

So I'm writing my first test class and I'm stuck. For my custom controller I adapted a sample wrapper class to my needs. Right now I'm getting 77% coverage but I need to define the selected boolean in my outside class to be true and I can't figure out how to do it. No matter what I try i keep getting an error that cMovie doesnt exist. How do I define cMovie in my test class so I can create an instance and set its boolean to true?

 

I've included my code below:

 

Apex Class:

public class RentalControllerWrapper {
    public List<cMovie> movieList {get;set;}
    public string movieIndex {get;set;}
    //contained class   
    public class cMovie {
         public Movie__c mov {get; set;}
         public Boolean selected {get; set;}
     
         //This is the contructor method. When we create a new cMovie object we pass a Movie that is set to the m property. We also set the selected value to false
         public cMovie(Movie__c m) {
             mov = m;
             selected = false;
         }
    }
     
     //This method uses a simple SOQL query to return a List of Movies
     public List<cMovie> getcMovie() {
         if(movieList == null) {
             movieList = new List<cMovie>();
             for(Movie__c m : [select Id, Name, price__c, description__c, total_inventory__c from Movie__c]) {
                 // As each contact is processed we create a new cMovie object and add it to the movieList
                 movieList.add(new cMovie(m));                 
             }
             //system.debug(movieList[0].mov.id);
         }
         return movieList;
     }
     
     public PageReference RentAllChecked() {
     //We create a new list of Movies if they are selected
     List<Movie__c> selectedMovies = new List<Movie__c>();
     //We will cycle through our list of cContacts and will check to see if the selected property is set to true, if it is we add the Movie to the selectedMovies list
     for(cMovie cMov : getcMovie()) {
         if(cMov.selected == true) {
             selectedMovies.add(cMov.mov);
         }
      }   
      // create new rental record
      Rentals__c newRentalRecord = new Rentals__c();
      insert newRentalRecord;
      
      for(Movie__c mv : selectedMovies) {
         //system.debug(mv);
         mv.total_inventory__c=mv.total_inventory__c-1;
         update mv;         
         // Create new Unit Rental Record and Insert
         Unit_Rental__c newUnitRentalRecord = new Unit_Rental__c();
         newUnitRentalRecord.Movie__c =  mv.ID;
         newUnitRentalRecord.Rental__c = newRentalRecord.ID;   
         insert newUnitRentalRecord;   
      }
      // Redirect to Success page passing rental record ID
      PageReference p = Page.RentalSuccess;
      p.getParameters().put('id', newRentalRecord.ID);
      p.setRedirect(true);
      return p; 
     }
     
     public PageReference Rent() { 
         for(cMovie cMov : getcMovie()) {
            if (cMov.mov.id==movieIndex){
                cMov.selected=true;                
            }
        }
      
        return null;           
     }

 

 

Test Class:

@isTest
private class RentalControllerWrapperTest {

    public static testMethod void RentalControllerWrapper() {
        Movie__c testmov=new Movie__c(Name='Movie1',Release_Date__c=System.now(),Description__c='Description',Price__c=1,Total_Inventory__c=10);
        insert testmov;     
               
        string movieIndex=testmov.ID; 
              
        Test.StartTest();
        RentalControllerWrapper controller=new RentalControllerWrapper();
        
        //controller.List<cMovie> testCMov=new List<cMovie>();
       
        controller.RentAllChecked();
        controller.Rent();                
        
        Test.stopTest(); 
    }
    
}

 VF:

<apex:page controller="RentalControllerWrapper">
 <h1>Rent a Movie</h1><br/><br/>
 <h2>Please Pick movie(s) to rent:</h2>
 <apex:form >
 <apex:pageBlock >
     <apex:pageBlockTable value="{!cMovie}" var="movie_item" id="rentalTable">
         <apex:column headerValue="Movie Title">
             <apex:inputCheckbox id="movieChecked" value="{!movie_item.selected}"/>
             <apex:outputText value="{!movie_item.mov.name}"/>
         </apex:column>
         <apex:column headerValue="Description">
             <apex:outputText value="{!movie_item.mov.Description__c}"/>
         </apex:column>
         <apex:column headerValue="Price">
             <apex:outputText value="${!movie_item.mov.Price__c}"/>
         </apex:column>
         <apex:column headerValue="# In Stock">
             <apex:outputText value="{!movie_item.mov.Total_Inventory__c}"/>
         </apex:column>
         <apex:column headerValue="Rent It">
             <apex:commandButton value="Rent {!movie_item.mov.name}" action="{!rent}" oncomplete="action2();" rerender="rentalTable">             
             <apex:param name="movieIndex" value="{!movie_item.mov.ID}" assignTo="{!movieIndex}" />
             </apex:commandButton>
             <apex:actionFunction name="action2" action="{!rentAllChecked}"/>
         </apex:column>
     </apex:pageBlockTable><br/>
     <apex:commandButton id="rentAllChecked" value="Rent all Checked Movies" action="{!rentAllChecked}" rerender="rentalTable"/>             
    
 </apex:pageBlock>
 </apex:form>
</apex:page>

 

 

 

On a button click I want to call a method,perform some logic, and then call a pagereference (used elsewhere on the page as well) that then generates a redirect. Is it possible to call a PageReference from apex? If so what is the syntax to do so?

 

Thanks!

So I've posted on this learning project a few times now and I'm stuck again. I have two ways to rent a movie, a movie specific button created dynamically in the table and also a checkbox is available for each movie with a rent all checked movies button at the bottom.

 

I'm having a hard time with my code to keep track of the checked movies. Please let me know if you have any suggestions on how I could improve this or what I could use in the PageReference AddSelected. Am I making it more complicated than it has to be? 

 

public class RentalController {

   public List<Movie__c> movieList {get; set;}  
  
   public Movie__c movieToRent {get;set;}     
  
   public string movieIndex {get;set;}
  
   public Rentals__c newRentalRecord {get;set;}
  
   public string movieChecked {get;set;}
    
   List<Movie__c> checkedMovieList = new List<Movie__c>();
  
   // Used onClick for each movie checkbox
   public pageReference AddSelected () {
      for (Movie__c tempMovie : checkedMovieList) {
          if (tempMovie.ID==movieChecked) {
            // WRONG SYNTAX BELOW? NEED TO REMOVE MOVIE IF ALREADY WAS SELECTED BECAUSE ITS NOW BEING DESELECTED  
            //  checkedMovieList.remove(tempMovie);
          }
      }
      checkedMovieList.add([SELECT ID, name, description__c, price__c, total_inventory__c FROM Movie__c WHERE ID=:movieChecked]);
      return null;
   }  
     
   public RentalController () {
       movieList = [SELECT ID, name, description__c, price__c, total_inventory__c FROM Movie__c LIMIT 20];
   }
  
   // Used when Rental all Checked Movies button is selected
   public PageReference rentAllChecked () {
     Rentals__c newRentalRecord = new Rentals__c();
     insert newRentalRecord;
             
     for (movie__c tempMovieToRent : checkedMovieList) {
         tempMovieToRent.total_inventory__c=tempMovieToRent.total_inventory__c-1;
         update tempMovieToRent;        
         // Create new Unit Rental Record and Insert
         Unit_Rental__c newUnitRentalRecord = new Unit_Rental__c();
         newUnitRentalRecord.Movie__c =  tempMovieToRent.ID;
         newUnitRentalRecord.Rental__c = newRentalRecord.ID;  
         insert newUnitRentalRecord;              
     }
     
     // Redirect to Success page passing rental record ID
     PageReference p = Page.RentalSuccess;
     p.getParameters().put('id', newRentalRecord.ID);
     p.setRedirect(true);
     return p;
   }
  
   // Used when movie specific rental button is selected
   public PageReference rent() {
       // Query matching movie ID and assign as selected movie object
       movieToRent=[SELECT ID, name, total_inventory__c, price__c FROM Movie__C WHERE ID=:movieIndex];
  
       // Decrement movie inventory by 1
       movieToRent.total_inventory__c=movieToRent.total_inventory__c-1;
       update movieToRent;
      
       System.debug(movieToRent.name); //SUCCESS
      
       // Create new Rental Record and Insert
       Rentals__c newRentalRecord = new Rentals__c();
       insert newRentalRecord;
      
       // Create new Unit Rental Record and Insert
       Unit_Rental__c newUnitRentalRecord = new Unit_Rental__c();
       newUnitRentalRecord.Movie__c = movieToRent.ID;
       newUnitRentalRecord.Rental__c = newRentalRecord.ID;
       insert newUnitRentalRecord;
      
       // convert price to a string, should create seperate method for this
       string price;
       price= movieToRent.price__c.format();
      
       // Redirect to Success page passing movie name
       PageReference p = Page.RentalSuccess;
       p.getParameters().put('id', movieToRent.name);
       p.getParameters().put('price', price);
       p.setRedirect(true);
       return p;
    }       
}

 

<apex:page controller="RentalController"   >
 <h1>Rent a Movie</h1><br/><br/>
 <h2>Please Pick movie(s) to rent:</h2>
 <apex:form >
 <apex:pageBlock >
     <apex:pageBlockTable value="{!movieList}" var="movie_item" id="rentalTable">
         <apex:column headerValue="Movie Title">
             <apex:inputCheckbox id="movieChecked">
                 <apex:actionSupport event="onclick" action="{!AddSelected}" rerender="rentAllChecked">
                     <apex:param name="movieChecked" value="{!movie_item.ID}" assignTo="{!movieChecked}" />
                 </apex:actionSupport>
                
             </apex:inputCheckbox>
             <apex:outputText value="{!movie_item.name}"/>
         </apex:column>
         <apex:column headerValue="Description">
             <apex:outputText value="{!movie_item.Description__c}"/>
         </apex:column>
         <apex:column headerValue="Price">
             <apex:outputText value="${!movie_item.Price__c}"/>
         </apex:column>
         <apex:column headerValue="# In Stock">
             <apex:outputText value="{!movie_item.Total_Inventory__c}"/>
         </apex:column>
         <apex:column headerValue="Rent It">
             <apex:commandButton value="Rent {!movie_item.name}" action="{!rent}" rerender="rentalTable">             
             <apex:param name="movieIndex" value="{!movie_item.ID}" assignTo="{!movieIndex}" />
             </apex:commandButton>
         </apex:column>
     </apex:pageBlockTable><br/>
     <apex:commandButton id="rentAllChecked" value="Rent all Checked Movies" action="{!rentAllChecked}" rerender="rentalTable">             
         <!--<apex:param name="movieIndex" value="{!movie_item.ID}" assignTo="{!movieIndex}" />-->
     </apex:commandButton>  
 </apex:pageBlock>
 </apex:form>
</apex:page>

 

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!

 

I'm new to VF/apex and have run into a strange issue. I'm redirecting from one VF page to another and sometimes the second page comes up blank. If i open up the VF editor pane and press save it then appears correctly. Any idea what might be causing this?

 

Thanks!

I'm learning Apex/VF and have created a very simple movie rental app. They select a unique button for each movie in a table. Some updates are made and then I want to pass the movie ID to a second success page displaying the movie that was selected. What is the best way to approach passing this ID to the second page?

 

Thanks!

What is the difference between the following:

List<Movie__c> movieList {get; set;}

List<Movie__c> movieList = new List<Movie__c>{};

 I'm assuming the second will need getter and setter defined? I'm trying to learn when the new keyword is necessary and when it isn't.

 

Thanks!

I'm trying to create a simple app while learning visualforce/apex. I'm creating a table of movies available to rent and want to have a button for each movie allowing you to rent that movie and passing the movie name to a method that will remove one from the inventory. I'm still working on it but I'm getting a java.lang.IllegalArgumentException error when I click the button and not sure where im going wrong. I'm sure there's probably an obvious error in my approach but any help would be great! 



 

Here's a code snippet of the column containing the rent button:

 

<apex:column headerValue="Rent Movie">
    <apex:commandButton action="!Rent" value="Rent {!movie_item.name}">
        <apex:param name="id" value="{!movie_item.name}" />
    </apex:commandButton>
</apex:column>

 

 

here's my apex code in my controller extension:

 

public class MovieRentalExtension {

    private final Movie__c movie;

    public MovieRentalExtension(ApexPages.StandardSetController controller) {
        this.movie = (Movie__c)controller.getRecord();
    }
   
    public void Rent() {
        Id id = System.currentPageReference().getParameters().get('id');
        // rent movie code
       
    }
}

 

So I'm writing my first test class and I'm stuck. For my custom controller I adapted a sample wrapper class to my needs. Right now I'm getting 77% coverage but I need to define the selected boolean in my outside class to be true and I can't figure out how to do it. No matter what I try i keep getting an error that cMovie doesnt exist. How do I define cMovie in my test class so I can create an instance and set its boolean to true?

 

I've included my code below:

 

Apex Class:

public class RentalControllerWrapper {
    public List<cMovie> movieList {get;set;}
    public string movieIndex {get;set;}
    //contained class   
    public class cMovie {
         public Movie__c mov {get; set;}
         public Boolean selected {get; set;}
     
         //This is the contructor method. When we create a new cMovie object we pass a Movie that is set to the m property. We also set the selected value to false
         public cMovie(Movie__c m) {
             mov = m;
             selected = false;
         }
    }
     
     //This method uses a simple SOQL query to return a List of Movies
     public List<cMovie> getcMovie() {
         if(movieList == null) {
             movieList = new List<cMovie>();
             for(Movie__c m : [select Id, Name, price__c, description__c, total_inventory__c from Movie__c]) {
                 // As each contact is processed we create a new cMovie object and add it to the movieList
                 movieList.add(new cMovie(m));                 
             }
             //system.debug(movieList[0].mov.id);
         }
         return movieList;
     }
     
     public PageReference RentAllChecked() {
     //We create a new list of Movies if they are selected
     List<Movie__c> selectedMovies = new List<Movie__c>();
     //We will cycle through our list of cContacts and will check to see if the selected property is set to true, if it is we add the Movie to the selectedMovies list
     for(cMovie cMov : getcMovie()) {
         if(cMov.selected == true) {
             selectedMovies.add(cMov.mov);
         }
      }   
      // create new rental record
      Rentals__c newRentalRecord = new Rentals__c();
      insert newRentalRecord;
      
      for(Movie__c mv : selectedMovies) {
         //system.debug(mv);
         mv.total_inventory__c=mv.total_inventory__c-1;
         update mv;         
         // Create new Unit Rental Record and Insert
         Unit_Rental__c newUnitRentalRecord = new Unit_Rental__c();
         newUnitRentalRecord.Movie__c =  mv.ID;
         newUnitRentalRecord.Rental__c = newRentalRecord.ID;   
         insert newUnitRentalRecord;   
      }
      // Redirect to Success page passing rental record ID
      PageReference p = Page.RentalSuccess;
      p.getParameters().put('id', newRentalRecord.ID);
      p.setRedirect(true);
      return p; 
     }
     
     public PageReference Rent() { 
         for(cMovie cMov : getcMovie()) {
            if (cMov.mov.id==movieIndex){
                cMov.selected=true;                
            }
        }
      
        return null;           
     }

 

 

Test Class:

@isTest
private class RentalControllerWrapperTest {

    public static testMethod void RentalControllerWrapper() {
        Movie__c testmov=new Movie__c(Name='Movie1',Release_Date__c=System.now(),Description__c='Description',Price__c=1,Total_Inventory__c=10);
        insert testmov;     
               
        string movieIndex=testmov.ID; 
              
        Test.StartTest();
        RentalControllerWrapper controller=new RentalControllerWrapper();
        
        //controller.List<cMovie> testCMov=new List<cMovie>();
       
        controller.RentAllChecked();
        controller.Rent();                
        
        Test.stopTest(); 
    }
    
}

 VF:

<apex:page controller="RentalControllerWrapper">
 <h1>Rent a Movie</h1><br/><br/>
 <h2>Please Pick movie(s) to rent:</h2>
 <apex:form >
 <apex:pageBlock >
     <apex:pageBlockTable value="{!cMovie}" var="movie_item" id="rentalTable">
         <apex:column headerValue="Movie Title">
             <apex:inputCheckbox id="movieChecked" value="{!movie_item.selected}"/>
             <apex:outputText value="{!movie_item.mov.name}"/>
         </apex:column>
         <apex:column headerValue="Description">
             <apex:outputText value="{!movie_item.mov.Description__c}"/>
         </apex:column>
         <apex:column headerValue="Price">
             <apex:outputText value="${!movie_item.mov.Price__c}"/>
         </apex:column>
         <apex:column headerValue="# In Stock">
             <apex:outputText value="{!movie_item.mov.Total_Inventory__c}"/>
         </apex:column>
         <apex:column headerValue="Rent It">
             <apex:commandButton value="Rent {!movie_item.mov.name}" action="{!rent}" oncomplete="action2();" rerender="rentalTable">             
             <apex:param name="movieIndex" value="{!movie_item.mov.ID}" assignTo="{!movieIndex}" />
             </apex:commandButton>
             <apex:actionFunction name="action2" action="{!rentAllChecked}"/>
         </apex:column>
     </apex:pageBlockTable><br/>
     <apex:commandButton id="rentAllChecked" value="Rent all Checked Movies" action="{!rentAllChecked}" rerender="rentalTable"/>             
    
 </apex:pageBlock>
 </apex:form>
</apex:page>

 

 

 

So I've posted on this learning project a few times now and I'm stuck again. I have two ways to rent a movie, a movie specific button created dynamically in the table and also a checkbox is available for each movie with a rent all checked movies button at the bottom.

 

I'm having a hard time with my code to keep track of the checked movies. Please let me know if you have any suggestions on how I could improve this or what I could use in the PageReference AddSelected. Am I making it more complicated than it has to be? 

 

public class RentalController {

   public List<Movie__c> movieList {get; set;}  
  
   public Movie__c movieToRent {get;set;}     
  
   public string movieIndex {get;set;}
  
   public Rentals__c newRentalRecord {get;set;}
  
   public string movieChecked {get;set;}
    
   List<Movie__c> checkedMovieList = new List<Movie__c>();
  
   // Used onClick for each movie checkbox
   public pageReference AddSelected () {
      for (Movie__c tempMovie : checkedMovieList) {
          if (tempMovie.ID==movieChecked) {
            // WRONG SYNTAX BELOW? NEED TO REMOVE MOVIE IF ALREADY WAS SELECTED BECAUSE ITS NOW BEING DESELECTED  
            //  checkedMovieList.remove(tempMovie);
          }
      }
      checkedMovieList.add([SELECT ID, name, description__c, price__c, total_inventory__c FROM Movie__c WHERE ID=:movieChecked]);
      return null;
   }  
     
   public RentalController () {
       movieList = [SELECT ID, name, description__c, price__c, total_inventory__c FROM Movie__c LIMIT 20];
   }
  
   // Used when Rental all Checked Movies button is selected
   public PageReference rentAllChecked () {
     Rentals__c newRentalRecord = new Rentals__c();
     insert newRentalRecord;
             
     for (movie__c tempMovieToRent : checkedMovieList) {
         tempMovieToRent.total_inventory__c=tempMovieToRent.total_inventory__c-1;
         update tempMovieToRent;        
         // Create new Unit Rental Record and Insert
         Unit_Rental__c newUnitRentalRecord = new Unit_Rental__c();
         newUnitRentalRecord.Movie__c =  tempMovieToRent.ID;
         newUnitRentalRecord.Rental__c = newRentalRecord.ID;  
         insert newUnitRentalRecord;              
     }
     
     // Redirect to Success page passing rental record ID
     PageReference p = Page.RentalSuccess;
     p.getParameters().put('id', newRentalRecord.ID);
     p.setRedirect(true);
     return p;
   }
  
   // Used when movie specific rental button is selected
   public PageReference rent() {
       // Query matching movie ID and assign as selected movie object
       movieToRent=[SELECT ID, name, total_inventory__c, price__c FROM Movie__C WHERE ID=:movieIndex];
  
       // Decrement movie inventory by 1
       movieToRent.total_inventory__c=movieToRent.total_inventory__c-1;
       update movieToRent;
      
       System.debug(movieToRent.name); //SUCCESS
      
       // Create new Rental Record and Insert
       Rentals__c newRentalRecord = new Rentals__c();
       insert newRentalRecord;
      
       // Create new Unit Rental Record and Insert
       Unit_Rental__c newUnitRentalRecord = new Unit_Rental__c();
       newUnitRentalRecord.Movie__c = movieToRent.ID;
       newUnitRentalRecord.Rental__c = newRentalRecord.ID;
       insert newUnitRentalRecord;
      
       // convert price to a string, should create seperate method for this
       string price;
       price= movieToRent.price__c.format();
      
       // Redirect to Success page passing movie name
       PageReference p = Page.RentalSuccess;
       p.getParameters().put('id', movieToRent.name);
       p.getParameters().put('price', price);
       p.setRedirect(true);
       return p;
    }       
}

 

<apex:page controller="RentalController"   >
 <h1>Rent a Movie</h1><br/><br/>
 <h2>Please Pick movie(s) to rent:</h2>
 <apex:form >
 <apex:pageBlock >
     <apex:pageBlockTable value="{!movieList}" var="movie_item" id="rentalTable">
         <apex:column headerValue="Movie Title">
             <apex:inputCheckbox id="movieChecked">
                 <apex:actionSupport event="onclick" action="{!AddSelected}" rerender="rentAllChecked">
                     <apex:param name="movieChecked" value="{!movie_item.ID}" assignTo="{!movieChecked}" />
                 </apex:actionSupport>
                
             </apex:inputCheckbox>
             <apex:outputText value="{!movie_item.name}"/>
         </apex:column>
         <apex:column headerValue="Description">
             <apex:outputText value="{!movie_item.Description__c}"/>
         </apex:column>
         <apex:column headerValue="Price">
             <apex:outputText value="${!movie_item.Price__c}"/>
         </apex:column>
         <apex:column headerValue="# In Stock">
             <apex:outputText value="{!movie_item.Total_Inventory__c}"/>
         </apex:column>
         <apex:column headerValue="Rent It">
             <apex:commandButton value="Rent {!movie_item.name}" action="{!rent}" rerender="rentalTable">             
             <apex:param name="movieIndex" value="{!movie_item.ID}" assignTo="{!movieIndex}" />
             </apex:commandButton>
         </apex:column>
     </apex:pageBlockTable><br/>
     <apex:commandButton id="rentAllChecked" value="Rent all Checked Movies" action="{!rentAllChecked}" rerender="rentalTable">             
         <!--<apex:param name="movieIndex" value="{!movie_item.ID}" assignTo="{!movieIndex}" />-->
     </apex:commandButton>  
 </apex:pageBlock>
 </apex:form>
</apex:page>

 

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!

 

I'm learning Apex/VF and have created a very simple movie rental app. They select a unique button for each movie in a table. Some updates are made and then I want to pass the movie ID to a second success page displaying the movie that was selected. What is the best way to approach passing this ID to the second page?

 

Thanks!

What is the difference between the following:

List<Movie__c> movieList {get; set;}

List<Movie__c> movieList = new List<Movie__c>{};

 I'm assuming the second will need getter and setter defined? I'm trying to learn when the new keyword is necessary and when it isn't.

 

Thanks!

I'm trying to create a simple app while learning visualforce/apex. I'm creating a table of movies available to rent and want to have a button for each movie allowing you to rent that movie and passing the movie name to a method that will remove one from the inventory. I'm still working on it but I'm getting a java.lang.IllegalArgumentException error when I click the button and not sure where im going wrong. I'm sure there's probably an obvious error in my approach but any help would be great! 



 

Here's a code snippet of the column containing the rent button:

 

<apex:column headerValue="Rent Movie">
    <apex:commandButton action="!Rent" value="Rent {!movie_item.name}">
        <apex:param name="id" value="{!movie_item.name}" />
    </apex:commandButton>
</apex:column>

 

 

here's my apex code in my controller extension:

 

public class MovieRentalExtension {

    private final Movie__c movie;

    public MovieRentalExtension(ApexPages.StandardSetController controller) {
        this.movie = (Movie__c)controller.getRecord();
    }
   
    public void Rent() {
        Id id = System.currentPageReference().getParameters().get('id');
        // rent movie code
       
    }
}

 

Hi,

 

I am very new to salesforce. I Observed most of the application are designed by wrapper classes in my Organization.

Can you please share some real time code samples regarding to wrapper class.

Please tell me where we use wrapper class exactly?

It  helps to understand wrapper classes easily. Your help will be greatly helps to me.

 

Thanks

ANKITA