简体   繁体   中英

Error while creating a record through salesforce API

While Running the below Code,

private static void createAccounts() {

    Itil_b__Incident__c[] records = new Itil_b__Incident__c[5];

    try {

      // create 5 test accounts
      for (int i=0;i<1;i++) {
        Itil_b__Incident__c a = new Itil_b__Incident__c();
        a.setCurrencyIsoCode("USD");
        a.setIsDeleted(Boolean.FALSE);
        a.setItil_b__Age_Minutes__c(29d);
        a.setHas_Managed_Services__c(Boolean.FALSE);
        a.setItil_b__Priority_from_ITIL_Matrix__c("Medium");
        a.setItil_b__Priority__c("Medium");
        a.setItil_b__Description__c("Testing API Descrition");
        a.setRank_Zero__c(Boolean.FALSE);
        a.setItil_b__Close_With_Problem__c(Boolean.FALSE);
        a.setItil_b__Subject__c("Test from API");
        a.setItil_b__Origin__c("Phone");
        a.setItil_b__Age__c("29 Days");
        a.setItil_b__Status__c("New");
        a.setAssigned_for_Today__c(Boolean.FALSE);
        a.setItil_b__Urgency__c("P4 - Low");
        a.setItil_b__Category__c("Request");
        a.setItil_b__Impact__c("Low");
        a.setSeverity__c("Sev4");   
        records[i] = a;
      }

      // create the records in Salesforce.com
      SaveResult[] saveResults = connection.create(records);

      // check the returned results for any errors
      for (int i=0; i< saveResults.length; i++) {
        if (saveResults[i].isSuccess()) {
          System.out.println(i+". Successfully created record - Id: " + saveResults[i].getId());
        } else {  
          Error[] errors = saveResults[i].getErrors();
          for (int j=0; j< errors.length; j++) {
            System.out.println("ERROR creating record: " + errors[j].getMessage());
          }
        }    
      }

    } catch (Exception e) {
      e.printStackTrace();
    }    

  }

I am getting the below error in the saveResults line,

[InvalidSObjectFault [ApiQueryFault [ApiFault  exceptionCode='INVALID_TYPE'
 exceptionMessage='Must send a concrete entity type.'
]
 row='-1'
 column='-1'
]
]

i am creating a new record in custom sObject [Itil_b__Incident__c] through Java API, can you please help what i might be missing?

Check your for loop. You currently have for (int i = 0; i < 1; i++) { Your comment says that you want to create 5 objects, so it should be for (int i=0; i<5; i++) { .

Also, I am not familiar with the Java API - I use a Python API. Usually in my cases, I need to serialize my objects into JSON since I am using a REST API. Does the Java API automatically doe the JSON serialization for you in the create method? Do your Itil_b__Incident__c objects have a toJson() method that returns a JSON string?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM