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
Reddy@SFDCReddy@SFDC 

System.ListException: List index out of bounds: 0 error

Hi, my code as follows

global class InboundLinxUserRegistration {
      global class dtRegistrationInput {
      webservice ID UserId;
      webservice String First_Name;
      webservice String Last_Name;
      webservice String Email_Address;
      webservice String Status;
      webservice ID Workplace_Id;
      webservice String Workplace_Name;
      webservice String Workplace_Province;
      webservice String Workplace_City;
      webservice String Workplace_Postal_Code;
      webservice String Workplace_Address;
      webservice String Speciality;
      webservice String Record_Type;
        }
     global class dtRegistrationOutput {
       webservice String status;
       webservice String Message_Text;
      }
     
      public webservice static dtRegistrationOutput Registration(dtRegistrationInput Registration){
           dtRegistrationOutput retvalue=new dtRegistrationOutput();
           retvalue.status='Success';
                          
            List<Account> account=new List<Account>();
                             
                     account[0].National_Code__c=Registration.UserId;
                     account[0].FirstName=Registration.First_Name;
                     account[0].LastName=Registration.Last_Name;
                     account[0].PersonEmail=Registration.Email_Address;
                     account[0].Account_Status_NES__c=Registration.Status;
                     account[0].Primary_Parent_vod__c=Registration.Workplace_Id;
                     account[0].Primary_Province_NES__c=Registration.Workplace_Province;
                     account[0].Primary_City_NES__c=Registration.Workplace_City;
                     account[0].Primary_Postal_Code_NES__c=Registration.Workplace_Postal_Code;
                     account[0].Primary_Address_1_NES__c=Registration.Workplace_Address;
                     account[0].Specialty_1_vod__c=Registration.Speciality;
                     account[0].RecordTypeId=Registration.Record_Type;
                     try{
                          insert account[0];
                         } catch (Exception e){
                            retvalue.Status='Failure';
                            retvalue.Message_Text= e.getMessage();
                           }
                  
          return retvalue;
       }
  }   

 

when i am trying this code with xmlspy i am getting the error

<

faultcode>soapenv:Client</faultcode><faultstring>System.ListException: List index out of bounds: 0

Class.InboundLinxUserRegistration.Registration: line 28, column 30

External entry point

</faultstring>

Best Answer chosen by Admin (Salesforce Developers) 
hchhch

On Account Object, the stnadard field for name is "Name" only. There are no fields like FirstName,LastName on Account Object. If you are using custom fields use __c at the end.

All Answers

hchhch

In the given code You are inserting only one record at a time. There is no need to declare the list of Accounts

 

Use following code:

 

Account acc = new Account();

acc.National_Code__c=Registration.UserId;

//assign all field values

try{
           insert acc;
} catch (Exception e){
          retvalue.Status='Failure';
           retvalue.Message_Text= e.getMessage();
   }

Reddy@SFDCReddy@SFDC

thank you,

                        but now i got new error as

  

Insert failed. First exception on row 0; first error: INVALID_FIELD_FOR_INSERT_UPDATE, Account: bad field names on insert/update call: LastName, FirstName: [LastName, FirstName]

</Message_Text>

hchhch

On Account Object, the stnadard field for name is "Name" only. There are no fields like FirstName,LastName on Account Object. If you are using custom fields use __c at the end.

This was selected as the best answer