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
tantoniotantonio 

Pageblocktable error - Unknown property 'listorgs' referenced in LoginHome

Hello, I am very new to writing both VF and Apex. I know this question is rudementary but I'm still struggling with getting the below solution to work. 

 

I am looking to create a visualforce page that will display all the records within a custom object I built, Org__c.

 

Below is the class I built to gather the data and pass into the pageblocktable. I'm assuming I have some extra code here that I could probably get rid of, as a side note. 

 

Global class listorgs
    implements iterator<org__c>{
        List<org__c> newlist {get; set;}
        Integer i {get; set;}
        
        public listorgs(){
            newlist = [select id, name from org__c];
            i = 0;
                }
        Global boolean hasnext(){
            if(i>= newlist.size()){
                return false;
            } else {
                return true;
            }
        }
        Global Org__c next(){
            if(i==100){return null;}
            i++;
            return newlist[i-1];
        }
}

    

 And here is the VFP. Note that I don't necessaryly have a variable called "name" but I just don't know what to put there. Any tips on that would be helpful as well as letting me know whats causing my VF to not be able to find the wrapper apex above.

 

<apex:page>

    <apex:form >
    
        <Apex:pageblock >
        <br/>
        <br/>
            <apex:commandButton value="Add Row" action="{!addrecord}" />
            
            <apex:pageblockTable value="{!listorgs}" var="name">
            
            </apex:pageblockTable>
        </Apex:pageblock>
        
    </apex:form>
    
</apex:page>

 

Thanks ahead of time for anyone who's willing to help!!

Best Answer chosen by Admin (Salesforce Developers) 
souvik9086souvik9086

Will you make that list variable public in controller? If not made it public public in controller otherwise vf can't able to find it.

 

If this post solves your problem kindly mark it as solution. if this post is helpful please throw Kudos.

Thanks

All Answers

souvik9086souvik9086

Hi,

 

Try this

 

you have to call the controller from apex:page and use newlist variable.

 

<apex:page controller="listorgs">

<apex:form >

<Apex:pageblock >
<br/>
<br/>
<apex:commandButton value="Add Row" action="{!addrecord}" />

<apex:pageblockTable value="{!newlist}" var="obj">
<apex:column>

<apex:outputfield value="obj.name"/>

</apex:column>
</apex:pageblockTable>
</Apex:pageblock>

</apex:form>

</apex:page>

 

and define the list in controller as

public List<org__c> newlist = new List<org__c>();

 

If this post solves your problem kindly mark it as solution. if this post is helpful please throw Kudos.

Thanks

tantoniotantonio

Thanks so much for the response and i see some of the things you did there and they make sense. Looks like the var="obj" is an opportunity to create a new variable to reference in the pageblocktable. That answers one question.

 

Also I made the modifications you suggested as well as I removed my "addrecords" because I don't have that defined in my listorgs class (I'm fine doing this, as the pageblocktable is more important at this time).

 

Here is the latest code and of course, the newest error :-) Lol

 

<apex:page controller="listorgs">

    <apex:form >
    
        <Apex:pageblock >
        <br/>
        <br/>
            
            <apex:pageblockTable value="{!newlist}" var="obj">
                <apex:column>
                    <Apex:outputField value="obj.name"/>
                </apex:column>
            </apex:pageblockTable>
        </Apex:pageblock>
        
    </apex:form>
    
</apex:page>

 

Error: Unkown property 'listorgs.newlist'

 

Thoughts?

souvik9086souvik9086

Will you make that list variable public in controller? If not made it public public in controller otherwise vf can't able to find it.

 

If this post solves your problem kindly mark it as solution. if this post is helpful please throw Kudos.

Thanks

This was selected as the best answer
tantoniotantonio

Fantastic! I also had to change the outputfield to outputtext because the object has mutli-currency. Not a problem however, all is working.

 

Thanks again, I will most definitly give kudos and mark as solved. Thanks again!

souvik9086souvik9086

Yes <apex:outputtext> is also supported.

 

Welcome. Anytime, anywhere :-)