You need to sign in to do that
Don't have an account?
MohanaGopal
List<SelectOption> componentList = null;
public List<SelectOption> getComponents()
{
componentList = new List<SelectOption>();
New_List__c[] p;
componentList.add(new selectoption('',''));
p=[select Id,Name from New_List__c where Measure__c='Control'];
if (p.size() >-1)
{
for(integer i = 0; i < p.size(); i++)
{
componentList.add(new selectoption(p[i].Id,p[i].Name));
}
}
return componentList;
}
public Control1(ApexPages.StandardController stdController)
{
this.calculatedControl = (Calculated_Measures__c)stdController.getRecord();
}
}
Null value Error in getter method
Hi...
In my visual force page I am using two get methods one is binding with inputfield and another one is inputtext...
If my get method query returns 0 record then it shows
System.QueryException: List has no rows for assignment to SObject
Class.Control1.getPerSav: line 11, column 7
External entry point
Class.Control1.getPerSav: line 11, column 7
External entry point
How to avoid it...
I saw a sample code for selectlist avoiding this error.. I have implemented it in following code..
Any one give sample code for avoiding those error in inputfield and inputtext...
Apex class
public class Control1
{
private Calculated_Measures__c calculatedControl;
{
private Calculated_Measures__c calculatedControl;
List<SelectOption> componentList = null;
public List<SelectOption> getComponents()
{
componentList = new List<SelectOption>();
New_List__c[] p;
componentList.add(new selectoption('',''));
p=[select Id,Name from New_List__c where Measure__c='Control'];
if (p.size() >-1)
{
for(integer i = 0; i < p.size(); i++)
{
componentList.add(new selectoption(p[i].Id,p[i].Name));
}
}
return componentList;
}
public Control1(ApexPages.StandardController stdController)
{
this.calculatedControl = (Calculated_Measures__c)stdController.getRecord();
}
}
you can declare the list outside like this.
List<SelectOption> componentList = new List<SelectOption>{};
or You can declare that list inside
List<SelectOption> componentList;
New_List__c[] p = new New_List__c[] ();
that way if the query is empty you won't be accessing undefined variable when you do
p.size()
Thanks
Its work properly..