1

This is my controller:

public with sharing class MyController {

    public myObject__c myObj {get; set;} 
    public String myObjectId;  

    public Boolean one;
    public Boolean two;
    public Boolean three;

    public MyController(ApexPages.StandardController standardController) {
        myObjectId = standardController.getRecord().id;
    }


    public MyController() {

        String query = 'SELECT id, one__c, two__c, three__c FROM myObject__c WHERE ID = :myObjectId LIMIT 1';

        myObject__c obj = database.query(query);

        one = plan.one__c;
        two = plan.two__c;
        three = plan.three__c;

    }

}

I want to pass one of the Boolean values into an alert on this page:

<apex:page standardController="StandardController" extensions="MyController">


    <script>

        alert('{!one}')

    </script>


</apex:page>

But Im getting the following error in Eclipse when I try to add the alert to me page:

Unknown Property: 'StandardController.one'

So it's looking in the StandarController for the value, when it should be looking in the extension.

Can anyone spot what I'm doing wrong here?

1
  • 3
    Its probably looking at both. You need a "getter"; one way to provide one is public Boolean one {get; set;}.
    – Keith C
    Commented Aug 27, 2014 at 19:28

1 Answer 1

4

As @Keith C said... you are missing your getters.. the rest of it looks fine. In the correction below, I have added getters and setters

public with sharing class MyController {

    public myObject__c myObj {get; set;} 
    public String myObjectId;  

    public Boolean one {get;set;}   /* <--- missing this */
    public Boolean two {get;set;}   /* <--- missing this */
    public Boolean three {get;set;} /* <--- missing this */

    public MyController(ApexPages.StandardController standardController) {
        myObjectId = standardController.getRecord().id;
    }


    public MyController() {

        String query = 'SELECT id, one__c, two__c, three__c FROM myObject__c WHERE ID = :myObjectId LIMIT 1';

        myObject__c obj = database.query(query);

        one = plan.one__c;
        two = plan.two__c;
        three = plan.three__c;

    }

}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .