You need to sign in to do that
Don't have an account?
❤Code
System.QueryException: List has no rows for assignment to SObject error using action:support
Hi All,
I am using action support to display data in textbox. But I am getting the below errros while executing -
Visualforce Error
Help for this Page
System.QueryException: List has no rows for assignment to SObject
Error is in expression '{!ContactPopulated}' in page autopu: Class.ManageListController.ContactPopulated: line 59, column 1
Class.ManageListController.ContactPopulated: line 59, column 1
Below is my apex class and vf page -
Apex Class -
public class ManageListController
{
public List<AccountWrapper> wrappers {get; set;}
public static Integer toDelIdent {get; set;}
public static Integer addCount {get; set;}
private Integer nextIdent=0;
public Custom_Package__c wimsContact {get;set;}
public String S {get;set;}
public ManageListController()
{
wrappers=new List<AccountWrapper>();
for (Integer idx=0; idx<5; idx++)
{
wrappers.add(new AccountWrapper(nextIdent++));
}
}
public void delWrapper()
{
Integer toDelPos=-1;
for (Integer idx=0; idx<wrappers.size(); idx++)
{
if (wrappers[idx].ident==toDelIdent)
{
toDelPos=idx;
}
}
if (-1!=toDelPos)
{
wrappers.remove(toDelPos);
}
}
public void addRows()
{
for (Integer idx=0; idx<addCount; idx++)
{
wrappers.add(new AccountWrapper(nextIdent++));
}
}
public PageReference save()
{
List<Custom_Package__c> accs=new List<Custom_Package__c>();
for (AccountWrapper wrap : wrappers)
{
accs.add(wrap.acc);
}
insert accs;
return new PageReference('/' + Schema.getGlobalDescribe().get('Custom_Package__c').getDescribe().getKeyPrefix() + '/o');
}
public void ContactPopulated(){
wimsContact =[select Per_Unit_Open_Rate__c,Space_Discount__c,Space_Unit__c,Circulation__c,First_Issue__c,Last_Issue__c,State__c,id,name, Market__c from Custom_Package__c where Name =:S];
system.debug('@@@@' + wimsContact );
}
public class AccountWrapper
{
public Custom_Package__c acc {get; private set;}
public Integer ident {get; private set;}
public AccountWrapper(Integer inIdent)
{
ident=inIdent;
acc=new Custom_Package__c();
}
}
}
VF Page -
<apex:page tabstyle="Account" controller="ManageListController">
<apex:form >
<apex:pageBlock title="Custom Package" id="thePageBlock">
<apex:pageBlockTable value="{!wrappers}" var="wrapper" id="wtable">
<apex:column headerValue="Ident">
<apex:outputText value="{!wrapper.ident}"/>
</apex:column>
<apex:column headerValue="Name">
<apex:inputText value="{!S}">
<apex:actionSupport event="onchange" action="{!ContactPopulated}" rerender="thePageBlock" status="status"/>
</apex:inputText>
<apex:actionStatus startText="applying address..." id="status"/>
</apex:column>
<apex:column headerValue="Market">
<apex:inputField value="{!wrapper.acc.Market__c}"/>
</apex:column>
<apex:column headerValue="State">
<apex:inputField value="{!wrapper.acc.State__c}"/>
</apex:column>
<apex:column headerValue="Action">
<apex:commandButton value="Delete" action="{!delWrapper}" rerender="wtable">
<apex:param name="toDelIdent" value="{!wrapper.ident}" assignTo="{!toDelIdent}"/>
</apex:commandButton>
</apex:column>
</apex:pageBlockTable>
<apex:commandButton value="Add Row" action="{!addRows}" rerender="wtable">
<apex:param name="addCount" value="1" assignTo="{!addCount}"/>
</apex:commandButton>
<apex:commandButton value="Add 5 Rows" action="{!addRows}" rerender="wtable">
<apex:param name="addCount" value="5" assignTo="{!addCount}"/>
</apex:commandButton>
<apex:commandButton value="Save" action="{!save}"/>
</apex:pageBlock>
</apex:form>
</apex:page>
Regards
I am using action support to display data in textbox. But I am getting the below errros while executing -
Visualforce Error
Help for this Page
System.QueryException: List has no rows for assignment to SObject
Error is in expression '{!ContactPopulated}' in page autopu: Class.ManageListController.ContactPopulated: line 59, column 1
Class.ManageListController.ContactPopulated: line 59, column 1
Below is my apex class and vf page -
Apex Class -
public class ManageListController
{
public List<AccountWrapper> wrappers {get; set;}
public static Integer toDelIdent {get; set;}
public static Integer addCount {get; set;}
private Integer nextIdent=0;
public Custom_Package__c wimsContact {get;set;}
public String S {get;set;}
public ManageListController()
{
wrappers=new List<AccountWrapper>();
for (Integer idx=0; idx<5; idx++)
{
wrappers.add(new AccountWrapper(nextIdent++));
}
}
public void delWrapper()
{
Integer toDelPos=-1;
for (Integer idx=0; idx<wrappers.size(); idx++)
{
if (wrappers[idx].ident==toDelIdent)
{
toDelPos=idx;
}
}
if (-1!=toDelPos)
{
wrappers.remove(toDelPos);
}
}
public void addRows()
{
for (Integer idx=0; idx<addCount; idx++)
{
wrappers.add(new AccountWrapper(nextIdent++));
}
}
public PageReference save()
{
List<Custom_Package__c> accs=new List<Custom_Package__c>();
for (AccountWrapper wrap : wrappers)
{
accs.add(wrap.acc);
}
insert accs;
return new PageReference('/' + Schema.getGlobalDescribe().get('Custom_Package__c').getDescribe().getKeyPrefix() + '/o');
}
public void ContactPopulated(){
wimsContact =[select Per_Unit_Open_Rate__c,Space_Discount__c,Space_Unit__c,Circulation__c,First_Issue__c,Last_Issue__c,State__c,id,name, Market__c from Custom_Package__c where Name =:S];
system.debug('@@@@' + wimsContact );
}
public class AccountWrapper
{
public Custom_Package__c acc {get; private set;}
public Integer ident {get; private set;}
public AccountWrapper(Integer inIdent)
{
ident=inIdent;
acc=new Custom_Package__c();
}
}
}
VF Page -
<apex:page tabstyle="Account" controller="ManageListController">
<apex:form >
<apex:pageBlock title="Custom Package" id="thePageBlock">
<apex:pageBlockTable value="{!wrappers}" var="wrapper" id="wtable">
<apex:column headerValue="Ident">
<apex:outputText value="{!wrapper.ident}"/>
</apex:column>
<apex:column headerValue="Name">
<apex:inputText value="{!S}">
<apex:actionSupport event="onchange" action="{!ContactPopulated}" rerender="thePageBlock" status="status"/>
</apex:inputText>
<apex:actionStatus startText="applying address..." id="status"/>
</apex:column>
<apex:column headerValue="Market">
<apex:inputField value="{!wrapper.acc.Market__c}"/>
</apex:column>
<apex:column headerValue="State">
<apex:inputField value="{!wrapper.acc.State__c}"/>
</apex:column>
<apex:column headerValue="Action">
<apex:commandButton value="Delete" action="{!delWrapper}" rerender="wtable">
<apex:param name="toDelIdent" value="{!wrapper.ident}" assignTo="{!toDelIdent}"/>
</apex:commandButton>
</apex:column>
</apex:pageBlockTable>
<apex:commandButton value="Add Row" action="{!addRows}" rerender="wtable">
<apex:param name="addCount" value="1" assignTo="{!addCount}"/>
</apex:commandButton>
<apex:commandButton value="Add 5 Rows" action="{!addRows}" rerender="wtable">
<apex:param name="addCount" value="5" assignTo="{!addCount}"/>
</apex:commandButton>
<apex:commandButton value="Save" action="{!save}"/>
</apex:pageBlock>
</apex:form>
</apex:page>
Regards
This error means that your query nothing found. I recomend you to use list of records instead of single.
See code below
Thanks,
Alex
The error got resolved. But i am facing another issue. While debugging i am not able to get the value S which i have used in textbox.
<apex:inputText value="{!S}">. Can u please let me know where i am doing the mistake.
Regards
Hi Alexander,
The UI looks like below. Once Name is typed , automatically market and state should get populated.
Regards