0

vf page is

<apex:page standardController="QuickCase__c" extensions="qs">
<apex:pageBlock title="Nominate user">
<apex:pageblockTable value="{!QuickCase__c}" var="quick">
<apex:column value="{!quick.Name}"/>


</apex:pageblockTable>

</apex:pageBlock>

</apex:page>

class

public with sharing class qs {
    List<Quickcase__c> Quick = new list<Quickcase__c>();
    public qs(ApexPages.StandardController controller) {


    }
    public qs  ()
{
Quick = [select id ,Name from Quickcase__c limit 5];
}


}
1
  • 2
    Hi Niranjan, welcome to SFSE. Pleases take a moment to visit the help center, scroll through the tour, and read How to Ask. What is it you are trying to accomplish? How does the observed behavior fall short? It is very difficult to help you when you offer so little description. The more specific you are, the better chance someone will help you.
    – Adrian Larson
    Jun 3, 2017 at 13:46

2 Answers 2

0

You need to change your code in following way.

Visualforce

<apex:page standardController="QuickCase__c" extensions="qs" action="{!init}">
    <apex:pageBlock title="Nominate user">
        <apex:pageblockTable value="{!Quick}" var="qk">
        <apex:column value="{!qk.Name}"/>
        </apex:pageblockTable>
    </apex:pageBlock>
</apex:page>

Controller

public with sharing class qs 
{
    public List<Quickcase__c> Quick {get;set;}
    public qs(ApexPages.StandardController controller) {

    }
    public void init()
    {
        Quick = [select id ,Name from Quickcase__c limit 5];
    }
}

Note: following changes have been made.

  1. Rather than using second no argument constructor, changed it to init() method which is getting called from apex:page action.

  2. Instead of using List<Quickcase__c> Quick = new list<Quickcase__c>();, following public getter-setter used: public List<Quickcase__c> Quick {get;set;}

  3. You have incorrectly used <apex:pageblockTable value="{!QuickCase__c}", value should expect List of records.

I should suggest you go through trailheads to learn Visualforce.

3
  • init is not necessary, and in fact, I would argue not a best practice. Objects should generally be initialized in their constructor.
    – sfdcfox
    Jun 5, 2017 at 2:27
  • is that be a good practice to use SOQL query in constructor, pls let me know Jun 5, 2017 at 2:32
  • For a Visualforce controller or extension, we should use queries in the constructor if we need to. We shouldn't use them if we don't need to, of course, but there's no reason why we should use an action method for the sole purpose of writing a query. Action methods are typically reserved for callouts, DML operations, and redirects, none of which you can do in a constructor.
    – sfdcfox
    Jun 5, 2017 at 2:46
1

You should initialize your extension in its one-parameter constructor. Also, you can't bind to the standard object to iterate over the query you've written, but instead need a public variable to bind to. The following changes would be appropriate for your code:


<apex:page standardController="QuickCase__c" extensions="qs">
  <apex:pageBlock title="Nominate user">
    <apex:pageblockTable value="{!quickCaseList}" var="quick">
      <apex:column value="{!quick.Name}"/>
    </apex:pageblockTable>
  </apex:pageBlock>
</apex:page>

public with sharing class qs {
  public List<Quickcase__c> quickCaseList { get; set; }
  public qs(ApexPages.StandardController controller) {
    quickCaseList = [select Name from Quickcase__c limit 5];
  }
}

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