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
The WalrusThe Walrus 

Error trying first example in the Apex language reference manual

I'm sure it's me, but...

 

On pages 27-29 of the Apex language reference manual, there is an example that creates a custom object (book_c and a custom field within the object Price_c).   Then,  a sample for loop within an apex class is demonstrated with the code below:

 

public class MyHelloWorld {
  public static void applyDiscount(Book_c[] books){
for (Book_c  b  :books) {
    b.Price_c *= 0.9; 
   }
  }   
}

 

However, when I try to build this code , I get the following error:

 

Error:Compile Error: Invalid type: Book_c at line 3 column 6

 

Like I said, I'm sure it's me but...why is this not working?

 

Thanks for any assistance

Best Answer chosen by Admin (Salesforce Developers) 
crop1645crop1645

It is Book__c (two underscores)

All Answers

The WalrusThe Walrus

Correction - the custom object is called Book_c, not book_c

crop1645crop1645

It is Book__c (two underscores)

This was selected as the best answer
Kate123Kate123

Also make sure that you have created the Book custom object in the previous step.

The WalrusThe Walrus

Thank you both very much.  The double underscore was my problem.