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
ch ranjeethch ranjeeth 

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="{}" />

<apex:column headerValue="Name">{!} </apex:column>


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');
        return ref;

       list<account> acclist=new list<account>();
    public list<account> getRecords()
       acclist=[select id,name from account];
      return acclist;

James LoghryJames Loghry
Where's your question?

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:

Your apex:page element would then look like the following:
<apex:page controller="Account" extensions="deleteclass">

Also, you would add an extension constructor to your deleteclass:

public deleteclass(ApexPages.StandardController ctrl){
    rid = ctrl.getId();
    //You could also add the account itself as a member variable like this:
    myAccount = (Account)ctrl.getRecord();

For additional Standard Controller methods, also see the following link: