I have a custom setting with one profile assigned to it and that's Heathrow portal. It has a field called Largest Number and a value assigned to it. I need to display that number on a visualforce page using apex class. My method doesn't seem to be working.
On the top of the visualforce page I assigned the page to the custom setting

**<apex:page sidebar="false" standardStylesheets="false" controller="GenerateNumber"  showHeader="false" title="Contact us">

and that seems to be fine but when I try to write a method that just returns the number it's failing and giving me a lot of errors.

public class GenerateNumber {

     public String numbersgenerated {get;set;}
     public String userinput {get;set;}

public GenerateNumber(){}

     public PageReference getNumbers() {
        return [SELECT Largest_Number__c FROM Number_Setting__c];
  • 2
    why return type PageReference ? this should be list<Number_Setting__c>
    – Ratan Paul
    Mar 1, 2016 at 14:35
  • It only hods one value do i still need to use the list ? and do i need to connect it to a command button on the visualforce page to get it retuned on the page ?
    – user26057
    Mar 1, 2016 at 14:41
  • 1
    Yes this should be list because query always return list until you put limit 1.. And in VF page you can use <apex:repeat to iterate over this list..
    – Ratan Paul
    Mar 1, 2016 at 14:43
  • what would i have to use if i wanted to display it once a button is pressed ?
    – user26057
    Mar 1, 2016 at 14:45

1 Answer 1


try simple approach. Declare a public variable

public Decimal largenum {get;set;}

and in the method assign value

list<Number_Setting__c> cslist = [SELECT Largest_Number__c FROM Number_Setting__c];

if(cslist.size() >0)
largeNum = cslist[0].Largest_Number__c;

and use it in the VF page.

  • 1
    Tushar no problem ..
    – Ratan Paul
    Mar 1, 2016 at 14:49
  • do i need to have any return statements to get it returned on the website ?
    – user26057
    Mar 1, 2016 at 14:51
  • 2
    @Greg no need any return statements just use largeNum and when you click on button don't forget to rerender the section where you are displaying largeNum .
    – Ratan Paul
    Mar 1, 2016 at 14:54
  • it comes up with the following error : Non-void method might not return a value or might have statement after a return statement, does anyone know how to fix it ?
    – user26057
    Mar 1, 2016 at 14:58
  • 1
    @Greg change your method return type to void and remove return statement. Mar 1, 2016 at 15:04

You must log in to answer this question.