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
nagamalli tadikondanagamalli tadikonda 

Missing id at index: 0

This is my vf page:-
<apex:page standardController="Account" extensions="StandardController1">
<apex:form >
<apex:pageBlock title="Account">
<apex:pageBlockTable value="{!accs}" var="a">
<apex:column value="{!a.name}"/>
<apex:column value="{!a.industry}"/>
</apex:pageBlockTable>
<apex:pageBlockButtons location="top">
<apex:commandButton value="submit" action="{!submit}"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
 This is my apex:-
public class StandardController1 {
public List<Account> accs {set;get;}
Account acc {set;get;}
public StandardController1(ApexPages.StandardController controller){
String[] fields = new String[]{'name','industry'};
    accs = new List<Account>();
controller.addFields(fields);
acc = (Account)controller.getRecord();
accs.add(acc);
}
public PageReference submit(){
Database.delete(accs,false);
PageReference p = new PageReference('/001/o');
return p;
}
}

i am getting this error:--- Missing id at index: 0
Error is in expression '{!submit}' in component <apex:commandButton> in page standardcontroller1: Class.StandardController1.submit: line 12, column 1
An unexpected error has occurred. Your development organization has been notified.
Best Answer chosen by nagamalli tadikonda
Amit Chaudhary 8Amit Chaudhary 8
Please try below code
public class StandardController1 
{
	public List<Account> accs {set;get;}
	public Account acc {set;get;}
	
	public StandardController1(ApexPages.StandardController controller)
	{
		String[] fields = new String[]{'name','industry'};
		accs = new List<Account>();
		controller.addFields(fields);
		acc = (Account)controller.getRecord();
		if(acc.id != null)
		{
			acc = [select id from account where id =:acc.id ];
			accs.add(acc);
		}	
	}

	public PageReference submit()
	{
		if(accs.size() > 0 )
		{
			Database.delete(accs,false);
		}
		
		PageReference p = new PageReference('/001/o');
		return p;
	}
	
}

I hope you you are passing Account Record ID in URL

 

All Answers

Aniket Malvankar 10Aniket Malvankar 10
Hello Nagamalli,

Please add '/'

PageReference p = new PageReference('/001/o/');

Thanks
Aniket
nagamalli tadikondanagamalli tadikonda
i tried that one also, but still i am getting same problem....
Amit Chaudhary 8Amit Chaudhary 8
Please try below code
public class StandardController1 
{
	public List<Account> accs {set;get;}
	public Account acc {set;get;}
	
	public StandardController1(ApexPages.StandardController controller)
	{
		String[] fields = new String[]{'name','industry'};
		accs = new List<Account>();
		controller.addFields(fields);
		acc = (Account)controller.getRecord();
		if(acc.id != null)
		{
			acc = [select id from account where id =:acc.id ];
			accs.add(acc);
		}	
	}

	public PageReference submit()
	{
		if(accs.size() > 0 )
		{
			Database.delete(accs,false);
		}
		
		PageReference p = new PageReference('/001/o');
		return p;
	}
	
}

I hope you you are passing Account Record ID in URL

 
This was selected as the best answer
nagamalli tadikondanagamalli tadikonda
thanks so much...know i am not getting that error....