You need to sign in to do that
Don't have an account?
Sfdc11
Get the selected related list Records..
List<obj> arry=new List<obj>();
List<objc> sel=new List<obj>();
public vfpg(ApexPages.StandardSetController controller) {
arry = (List<obj>) controller.getSelected();
sel=[select Id,Total_General_Amount__c,Name from FTS__c where Id IN :obj];
System.debug('arr size'+sel.size()); // returning size correctly
System.debug('first rec'+sel[0]); // Getting Error here - List Index out of bounds exception.
If I print Array alone,it's returning the selected query record properly..
Why the prob when specify [0]..
Looking at your example code, I'm assuming this isn't the real code as it wouldn't compile.
Can you post the real code? There's no reason why the element of the array wouldn't be available from a conceptual point of view.
Real code:
public PVS__c PVS{get;set;}
List<PVS__c> arryPVS=new List<PVS__c>();
List<PVS__c> selPVS=new List<PVS__c>();
Decimal TotAmt=0.0;
public VFTestPage(ApexPages.StandardSetController controller) {
arryPVS= (List<PVS__c>) controller.getSelected();
System.debug('Selected PVS******'+arryFTS); -> returning the selected 2 records of related list
selPVS=[select Id,Total__Amt__c,Name from PVS__c where Id IN :arryPVS];
System.debug('Selected PVS******'+selPVS); ---> returning the selected 2 records
System.debug('Selected PVS******'+selPVS[0]); ---> Getting Error -List Index out of bounds exception
for(integer i=0;i<=selPVS.size();i++){
try{
PVS=[select Id,Total__Amt__c,Name from FTS__c where Id=:selPVS[i].Id];-> ---> Getting Error -List Index out of bounds exception
TotAmt=TotAmt+PVS.Total__Amt__c;
}
catch(Exception e){}
}
}
I'd expect a list out of bounds exception from this loop:
as if you have 2 records, your iterator will retrieve elements at index 0, 1 and 2. You need to change this so that the index is less than the size of the list:
I have no idea why you are getting a list out of bounds exception when accessing the zeroth element of the array - that makes no sense to me.
There's also a couple of areas that I don't understand in the code:
Where does arryFTS come from? This doesn't appear to be declared anywhere. Is this the code cut/pasted from your dev org? It looks like you've edited it again to make the errors clear, but could that mean you have inadvertently changed some of the code?