You need to sign in to do that
Don't have an account?
urgent:list index outof bounds0
Hi all ,
i have a custom vf page button.for this i wrote controller and vf page like this
public class accnext{public id idd{set;get;}public boolean error{set;get;}pagereference p;public accnext(ApexPages.StandardController controller) {
}public pagereference next(){
id aid=apexpages.currentPage().getParameters().get('id');
account[] acc=[select id,name,parentid from account where parentid=:aid];system.debug(acc[0].id);system.debug('***'+aid);system.debug(acc.size());idd=acc[0].id;system.debug(idd);if(acc.size()==0){error=true;}else{error=false;pagereference p1=new pagereference('/'+idd);return p1;}return null;}}
page
<apex:page standardController="account" sidebar="false" extensions="accnext" action="{!next}" > <apex:pageMessages /> <apex:detail relatedlist="true"/> <apex:outputpanel rendered="{!error}"> <apex:outputText > child record not found:</apex:outputText> </apex:outputpanel></apex:page>
its not working showing an error like the listoutofbounds exception. any one please can u help me ..
thanks in advance.....
anu.....
is your debug statements returning expected results?
Firstly you aren't checking if the id from page is coming or not,
And secondly, you are trying to access idd=acc[0].id when the list is blank.
So check both the things,
I have updated the code, please refer:
Hi,
Thank u for ur reply.
its working but my requirement is when the related child record is not there it showing msg like child record not found.but its not showing the msg redirected to same current page only.can u please send me any changes in this code.
My page is:
You have to check with proper condition and show appropriate Page messages.
I hope your checking with the url : /apex/accnext?Id='Some Id' .
Try below code.