I am coming across the above error while deleting a record from the database.
The vf page code is as follows
<apex:page controller="EditAll">
<apex:form >
<apex:sectionHeader title="Edit Contacts for" subtitle="{!c[0].Account.Name}"/>
<apex:pageBlock >
<apex:variable value="{!0}" var="rowNumber" />
<apex:outputPanel id="panelWithVar">
<apex:variable value="{!0}" var="rowNumber" />
</apex:outputPanel>
<apex:pageBlockButtons location="top">
<apex:commandButton value="Save" action="{!SaveMethod}"/>
<apex:commandButton value="Cancel" action="{!CancelMethod}"/>
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!c}" var="t" id="newItems">
<apex:column headerValue="Name">
<apex:OutputField value="{!t.Name}"/>
</apex:column>
<apex:column headerValue="Title">
<apex:inputField value="{!t.Title}"/>
</apex:column>
<apex:column headerValue="Email">
<apex:inputField value="{!t.Email}"/>
</apex:column>
<apex:column headerValue="Phone">
<apex:inputField value="{!t.Phone}"/>
</apex:column>
<apex:column headerValue="Amount">
<apex:inputField value="{!t.Amount__c}"/>
</apex:column>
<apex:column >
<apex:commandButton value="Remove" action="{!RemoveMethod}" reRender="newItems,panelWithVar">
<apex:param name="p1" value="{!rowNumber}" assignTo="{!numberOfRowToRemove}"/>
</apex:commandButton>
</apex:column>
<apex:column >
<apex:variable var="rowNumber" value="{!rowNumber + 1}" />
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
The apex class is as follows:
public class EditAll
{
public String ids{set;get;}
public List<Contact> c {set;get;}
public Integer numberOfRowToRemove {set;get;}
public Contact d;
public EditAll()
{
ids=ApexPages.currentPage().getParameters().get('id');
c = new List<Contact>([select Name, Title, Email , Id, Phone, Amount__c, accountid, Account.Name from contact where accountid=:ids]);
}
public PageReference SaveMethod()
{
update c;
return new PageReference('/'+ids);
}
public PageReference CancelMethod()
{
return new PageReference('/'+ids);
}
public PageReference RemoveMethod()
{
id rid = c.get(numberOfRowToRemove).id;
c.remove(numberOfRowToRemove);
delete [select id from Contact where id=: rid];
update c;
return null;
}
}
Could anyone please let me know how can i resolve the above error, or where can I make the code changes to get the error resolved ?