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
amorganamorgan 

bug: accessing innerclass properties more that once don't work

I have here an innerclass with a property that always returns 54. When I try to access the property more than once in a VisualForce Page then I get an unexpected result.

Expected Page Result:
54 - 54

Actual Page Result:
54 -

Notes:
Accessing the property twice in the testmethod works so this makes me think it's a VisualForce issue.

Page:
<apex:page controller="TestPageCon">
{!b.b} - {!b.b}
</apex:page>

Controller:
public class TestPageCon {
public class TestPageCon {
public class B {
public Integer b {
get {return 54;}
}
}

public B getB() {return new B();}

testmethod static void testBug() {
TestPageCon test = new TestPageCon();
System.assertEquals(test.getB().b, 54);
System.assertEquals(test.getB().b, 54);
}
}
Best Answer chosen by Admin (Salesforce Developers) 
SuzanyuSuzanyu
I did some change in your code and I get what you want.
The reason is you made the inner property "public" and same name with the B (even that is lower case) . And there are two getB() both public as well. The complier getting confused.
 
===============test results=====================
54 - 54 
 
public class TestPageCon {
       
    public class B {        
        private Integer b ;
        public Integer getB() {            
            return 54;        
         }    
     }       
    
    public B getB() 
    {
    return new B();}    
}