You need to sign in to do that
Don't have an account?

System.QueryException: List has no rows for assignment to SObject Error is in expression '{!Dodelete}' in page scenario2eg12: Class.deleteclass.Dodelete: line 6, column 1 Class.deleteclass.Dodelete: line 6, column 1
<apex:page controller="deleteclass">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:pageBlockTable value="{!records}" var="r">
<apex:column headerValue="action">
<apex:commandLink value="Delete" action="{!Dodelete}">
<apex:param name="rid" value="{r.id}" />
</apex:commandLink>
</apex:column>
<apex:column headerValue="Name">{!r.name} </apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Custom controller:
public with sharing class deleteclass {
public string rid{get;set;}
account acc1=new account();
public PageReference Dodelete() {
acc1=[select id,name from account where id=:rid];
delete acc1;
pagereference ref=new pagereference('/001?fcf=00B900000085iko');
ref.setredirect(true);
return ref;
}
list<account> acclist=new list<account>();
public list<account> getRecords()
{
acclist=[select id,name from account];
return acclist;
}
}
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
<apex:pageBlockTable value="{!records}" var="r">
<apex:column headerValue="action">
<apex:commandLink value="Delete" action="{!Dodelete}">
<apex:param name="rid" value="{r.id}" />
</apex:commandLink>
</apex:column>
<apex:column headerValue="Name">{!r.name} </apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Custom controller:
public with sharing class deleteclass {
public string rid{get;set;}
account acc1=new account();
public PageReference Dodelete() {
acc1=[select id,name from account where id=:rid];
delete acc1;
pagereference ref=new pagereference('/001?fcf=00B900000085iko');
ref.setredirect(true);
return ref;
}
list<account> acclist=new list<account>();
public list<account> getRecords()
{
acclist=[select id,name from account];
return acclist;
}
}
The error is coming from the following line: acc1=[select id,name from account where id=:rid];
You're not setting rid in your controller.
Try changing your visualforce page to use the standard Account controller, and then modify your apex class to be an extension rather than a stand alone controller...
See this for more info: http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_extension.htm
Your apex:page element would then look like the following:
Also, you would add an extension constructor to your deleteclass:
For additional Standard Controller methods, also see the following link: https://www.salesforce.com/us/developer/docs/pages/Content/apex_ApexPages_StandardController_methods.htm