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
bj9bj9 

Apex Workbook error - Invalid Constructor Name

public class StoreFrontController {

    List<DisplayMerchandise> products;
    
    public List<DisplayMerchandise> getProducts() {
        if(products == null) {
            products = new List<DisplayMerchandise>();
            for(Merchandise__c item : [
                    SELECT Id, Name, Description__c, Price__c, Total_Inventory__c
                    FROM Merchandise__c]) {
                products.add(new DisplayMerchandise(item));
            }
        }
        return products;
    }
    
    // Inner class to hold online store details for item    public class DisplayMerchandise {

        private Merchandise__c merchandise;
        public DisplayMerchandise(Merchandise__c item) {
            this.merchandise = item;
        }

        // Properties for use in the Visualforce view        public String name {
            get { return merchandise.Name; }
        }
        public String description {
            get { return merchandise.Description__c; }
        }
        public Decimal price {
            get { return merchandise.Price__c; }
        }
        public Boolean inStock {
            get { return (0 < merchandise.Total_Inventory__c); }
        }
        public Integer qtyToBuy { get; set; }
    }
}

 

This code snippet is obtain from Apex Workbook online Chapter 3, Tutorial #17 and Lessonr #5 "Using Inner Classes in an Apex Controller"

 

When I try to save this class I get an error saying

"Invalid Constructor Name : DisplayMerchandise" (line 20)

 

I have highlighted the line in red for easy reference.

 

Can someone tell me whats the issue with the class code ?

 

 

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

The problem is a couple of lines before - the class definition has been tacked on the end of a comment line:

 

  // Inner class to hold online store details for item    public class DisplayMerchandise {

 

Change this to:

 

  // Inner class to hold online store details for item
public class DisplayMerchandise {

 

All Answers

bob_buzzardbob_buzzard

The problem is a couple of lines before - the class definition has been tacked on the end of a comment line:

 

  // Inner class to hold online store details for item    public class DisplayMerchandise {

 

Change this to:

 

  // Inner class to hold online store details for item
public class DisplayMerchandise {

 

This was selected as the best answer
bj9bj9

Thanks !!!!!!!!