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
hiteshwar marnihiteshwar marni 

list outof bond exception

hiteshwar marnihiteshwar marni
public class EfileController {
public static blob contentFile1;
public static list<string>  filelines1;
public static string  filenam; 
public static Payer__c pr;
public static Payee__c py;
public static list<Payer__c>prList;
public static map<string,id>pay;

public static list<Payee__c>PYList;
@auraEnabled
public static list<Payee__c>payee{get;set;}
 
    @auraEnabled
    public static list<Payee__c> SaveFile(String base64Data) {
         base64Data = EncodingUtil.urlDecode(base64Data, 'utf-8');
        contentFile1=EncodingUtil.base64Decode(base64Data);
        filelines1 = new String[]{};
         filenam=contentFile1.toString();
        
        filelines1 = filenam.split('\n');
         payee= new list<Payee__c>();
         PYList= new list<Payee__c>();
         prList = new list<Payer__c>();
         system.debug('size##'+filelines1.size());
         
            for (Integer i=0;i<filelines1.size();i++)
            {
                
                String[] inputvalues = filelines1[i].split(',');
                if(inputvalues.size()>0){
                pr=new Payer__c();
                pr.name=inputvalues[1];
                prList.add(pr);
                 
            }}
            insert prList;
            insert PYList;
            pay=new map<string,id>();
            for(Payer__c p:prList){
              pay.put(p.name,p.id);   
            }
           
            for (Integer i=1;i<filelines1.size();i++)
            {
                
                String[] inputvalues = filelines1[i].split(',');
                 if(inputvalues.size()>0){
                py= new Payee__c();
                py.name=inputvalues[0];
                py.Payer__c=pay.get(inputvalues[1]);
                py.Tax_ID__c=inputvalues[2];
                py.Zip_Postal_code__c=inputvalues[3];
                //py.Amount__c=decimal.valueOf(inputvalues[3]);
                
                PYList.add(py);
               
    
            }}
            insert PYList;
            return PYList;
    }
}


i'm getting list out of bond exception 1 at  pr.name=inputvalues[1];please help me. my excel columns are


Payee NamePayerTax IDPayee Zip / Postal Code1099 Amount
v varaprasadv varaprasad
Hi ,

your list is not having values and you are assigning null values.Add debug logs and check once you are getting values or not.

system.debug('===inputvaluess=='+inputvalues);
system.debug('===inputvalues=='+inputvalues[1]);

    pr.name=inputvalues[1]; //Here you are assigning null values.



Hope this helps you!

Thanks
Varaprasad
@For Support: varaprasad4sfdc@gmail.com
Amit Chaudhary 8Amit Chaudhary 8
Please check below post for same
1) https://help.salesforce.com/articleView?id=000181121&type=1

If you then attempt to access an element at row 0, it'll throw an error as that row doesn't exist. It's good practice to check there are records first in order to make sure that the list is not empty before accessing it.

Check if list is empty
Before referring to the 0th index of list you must perform a check on whether the list is empty or not. Whenever you try to access records from list first check if its empty or not.
List lstAccount = [Select Id, Name from Account Limit 10];
// Before processing the list check if its empty or not
// It will go inside the loop only if the List is having values in it.
if(lstAccount.size() > 0) {
 // Do something with lstAccount[0].Name
 }
// If you try to access lstAccount[0] without empty check then it will obviously throw that error!!

Considerations for empty list
The query returned no rows to the List after execution.
You are also using those field(s) in your class or trigger.