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
Mayank Deshpande 22Mayank Deshpande 22 

Getting Nullpointerexception while using standard set controller. kindly suggest whats wrong in code

Apex code 

public with sharing class getopportunity {
public ApexPages.StandardSetController opty {
get {
 if (opty==null)
 {
 ApexPages.StandardSetController opty = New ApexPages.StandardSetController (Database.getquerylocator([select Name, CloseDate FROM Opportunity])); } 
 return opty;} 
 set;} 
 public List<Opportunity> getOpportunities() { 
 return (List<Opportunity>) opty.getRecords();} 
 }
sfdcMonkey.comsfdcMonkey.com
can you share vf page code here ?
thanks
Vidol ChalamovVidol Chalamov

Remove "ApexPages.StandardSetController" from " ApexPages.StandardSetController opty = New ApexPages.StandardSetController (Database.getquerylocator([select Name, CloseDate FROM Opportunity]));"

public with sharing class getopportunity {
	public ApexPages.StandardSetController opty {
		get {
			if (opty==null)
			{
				opty = New ApexPages.StandardSetController (Database.getquerylocator([select Name, CloseDate FROM Opportunity])); 
			} 
			return opty;
		} 
		set;
	} 

	public List<Opportunity> getOpportunities() { 
		return (List<Opportunity>) opty.getRecords();
	} 
}