private static void createCustomer() {
        Customer__c[] createCust = new Customer__c[5];
        try {
            Customer__c customer = new Customer__c();
            createCust[0]= customer;
            SaveResult[] saveResults = connection.create(createCust);
            if(saveResults[0].isSuccess()) {
                System.out.println("Successfully created customer ! - id:" + saveResults[0].getId());
            }else {
                Error[] errors = saveResults[0].getErrors();
                    System.out.println("Error :" + errors[0].getMessage());
        }catch(Exception e){

Hi, Here is my code. This is some few code where my error occurs.. Where Customer__c is my object name and the error indicates the line "SaveResult[] saveResults = connection.create(createCust);" Help would be great . Thanks in advance

  • why you are using connection.create() in your code? – sfdc_sk Jul 25 '19 at 10:30
  • So that it will create a new record in my indicated Sobject (Customer__c) – Lokesh Jul 26 '19 at 4:00
  • Connection is a variable for function ConnectorConfig – Lokesh Jul 26 '19 at 4:00

You only have one element created, but the array is 5 elements long. This would produce the error you've seen. Try this instead:

Customer__c[] createCust = new Customer__c[1]; // Allocate space for 1 element.
  • Thanks ! Appreciate the help – Lokesh Jul 26 '19 at 3:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.