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
אביב קסוטואביב קסוטו 

Read only property error on custom controller

I am trying to display a select list from a custom controller, and i get a "Read only property 'productsTitle'" error when trying to save the visualforce page.

My custom controller:
 

public class BpmIcountPayment{

    private final Account account;

    public String productsTitle {
      get { return 'products for sale'; }
    }
 
    public BpmIcountPayment() {
        account = [SELECT Id, Name, Site FROM Account
                   WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
    }

    public Account getAccount() {
        return account;
    }

    public List<SelectOption> getProductsLov() {
        List<SelectOption> products = new List<SelectOption>();
        List<Product2> productsList = [SELECT Name, Family 
                                      FROM Product2 
                                      WHERE (Family = 'ShopProduct') 
                                      OR (Family = 'CourseParent') 
                                      OR (Family = 'SFCourseProgram')];

        for (Product2 currProduct : productsList) {
            products.add(new SelectOption(currProduct.Id, currProduct.Name));
        }

        return products;
    }
}

And my visualforce page:

<apex:page Controller="BpmIcountPayment">
    <apex:param name="first_name" value="Account.FirstName"/>
    <apex:param name="last_name" value="Account.LastName"/>
    <apex:param name="id" value="Account.idnumber__c"/>
    <apex:param name="address" value="Account.Address"/>
    <apex:form>
        <apex:selectList value="{!productsTitle}" multiselect="false">
            <apex:selectOptions value="{!ProductsLov}"></apex:selectOptions>
        </apex:selectList>
    </apex:form>
</apex:page>
Best Answer chosen by אביב קסוטו
Raj VakatiRaj Vakati
Its wrong with your get and set method. you defined it as just get method and trying to set the values 
 
public String productsTitle {
      get { return 'products for sale'; }
    }

Change it below 

public String productsTitle {
    get {
       
        return 'products for sale';
    }
    set; 
}



 

All Answers

Raj VakatiRaj Vakati
Its wrong with your get and set method. you defined it as just get method and trying to set the values 
 
public String productsTitle {
      get { return 'products for sale'; }
    }

Change it below 

public String productsTitle {
    get {
       
        return 'products for sale';
    }
    set; 
}



 
This was selected as the best answer
אביב קסוטואביב קסוטו
Works like a charm! thank you!