Skip to main content
I'm going through SaleForce's tutorial for "Writing your first apex trigger (https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_qs_HelloWorld.htm)" and I don't understand what purpose the two "books" serve.  Book__c is a custom object that they had me create.

 

public class MyHelloWorld {

 

   public static void applyDiscount(Book__c[] books) {

 

      for (Book__c b :books){

 

         b.Price__c *= 0.9;

 

      }

 

   }

 

}

 

Thanks in advance.
3 respuestas
  1. 11 jul 2014, 20:15
    "books" is the variable reprensenting an Array of Book__c objects you are passing to your applyDiscount method. 

     

    When you create a method the items between the paratheses tell what inputs you are going to pass when you call the method. In this case when you want to call applyDiscount you are saying you are going to pass it an Array of Book_c objects and you are going to reference that Array with the variable "books". Then within that method you use that reference, which where you are using in a for loop. 

     

    The exact variable name is largely irrelevant. Other than a few reserved terms you could call it anything you want as long as that is what you use later in your method. If you wanted to call it "abc" this is how it would look: 

     

    ...

     

    public static void applyDiscount(Book__c[] abc) {

     

          for (Book__c b :abc){

     

    ...
0/9000