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
AKRAKR 

Trouble with custom objects / create

Hello,

 

I [new to this all] downloaded the �java getting started package� + java_samples.zip. I get Access to the API and everything works fine - I can create, edit and delete salesforce objects (leads, accounts, ⬦ ). But if I try to create a data record according to a custom object (I created an object named �reseller� in the salesforce UI with attributes �reseller_id� and �description� and wrote a function 'createReseller' according to 'createAccountSample'), following runtime error message shows up:

 

Failed to create reseller -  error message:

Tried to invoke method public common.api.soap.SaveResult[] common.api.soap.Soap.create(common.api.soap.Entity[]) throws org.apache.axis.AxisFault with arguments [Ljava.lang.Object;.  The arguments do not match the signature.; nested exception is:

java.lang.IllegalArgumentException: java.lang.ClassCastException@1cdd2a1

 

My application logs in as a sysadmin, also the reseller properties seem to be set correctly (creatable:true ⬦). The data types are correct. After producing objects from the WSDL file with WSDL2JAVA I changed nothing at the custom object in UI. What is going wrong?

 

Thanks in advance for your advice.
DevAngelDevAngel

Hi AKR,

Which version of the WSDL are you using?  Would you mind posting your createReseller function?  On inspection, can you see a generated class for reseller__c?

AKRAKR

Hello Dave,

I am using the company WDSL (not partner WDSL). On inspection I can see a generated class for reseller__c. Here comes the code of createReseller function:

private void createReseller() {
   
   //Verify that we are already authenticated, if not
   //call the login function to do so
   
   if (!loggedIn) {
    if (!login())
     return;
   }
   try {
    Reseller__c reseller;
    SObject[] sObjects = new SObject[1];
      
    reseller = new Reseller__c();
    reseller.setDescription__c("Test Test HA HA HA");
    //reseller.setReseller_ID__c(new Double (200));
         
    sObjects[0] = reseller;
     
    //create the object(s) by sending the array to the web service
    SaveResult[] sr = binding.create(sObjects);
    
    if (sr[0].isSuccess())  {
     System.out.println("Reseller was created with an id of: " + sr[0].getId().getValue());
    } else {
      //there were errors during the create call, go through the errors
     //array and write them to the screen
     
      //get the next error
      com.sforce.soap.enterprise.Error err = sr[0].getErrors()[0];
      System.out.println("Errors were found on item " + new Integer(0).toString());
      System.out.println("Error code is: " + err.getStatusCode().toString());
      System.out.println("Error message: " + err.getMessage());
    }
    getUserInput("\nHit return to continue...");
   }
   catch (UnexpectedErrorFault uef) {
    System.out.println(uef.getExceptionMessage());
   }
   catch (Exception ex) {
    System.out.println("\nFailed to create reseller -  error message: \n"
         + ex.getMessage());
    getUserInput("\nHit return to continue...");
   }

}

I'm looking forward to your response!

 

DevAngelDevAngel

Hi AKR,

Could you post the entire structure of your custom object please?  I am trying to reproduce.

 

Cheers

AKRAKR

 Hello Dave,

do you mean I should post the entire Reseller__c.java? This is an extract from my WSDL file:

<complexType name="Reseller__c">
                <complexContent>
                    <extension base="ens:sObject">
                        <sequence>
                        <element name="CreatedById" minOccurs="0" type="tns:ID"/>
                        <element name="CreatedDate" minOccurs="0" type="xsd:dateTime"/>
                        <element name="Description__c" minOccurs="0" type="xsd:string"/>
                        <element name="LastModifiedById" minOccurs="0" type="tns:ID"/>
                        <element name="LastModifiedDate" minOccurs="0" type="xsd:dateTime"/>
                        <element name="OwnerId" minOccurs="0" type="tns:ID"/>
                        <element name="Reseller_ID__c" minOccurs="0" type="xsd:double"/>
                        <element name="SystemModstamp" minOccurs="0" type="xsd:dateTime"/>
                        </sequence>
                    </extension>
                </complexContent>
            </complexType>
            <element name="Reseller__c" type="ens:Reseller__c"/>

 

DevAngelDevAngel

Hi AKR,

I just ran this function to create a custom object without error:

 private void createResellerSample()
 {
  //Verify that we are already authenticated, if not
  //call the login function to do so
  if (!loggedIn)
  {
   if (!login())
    return;
  }

  try
  {
   SObject[] records = new SObject[1];
   Reseller__c reseller;
   reseller = new Reseller__c();
   reseller.setDescription__c("Test Test HA HA HA");
   reseller.setReseller_ID__c(new Double(200));
   records[0] = reseller;
   
   //create the object(s) by sending the array to the web service
   SaveResult[] sr = binding.create(records);
   for (int j=0;j<sr.length;j++)
   {
    if (sr[j].isSuccess())
    {
     System.out.println("An reseller record was create with an id of: "
      + sr[j].getId().getValue());
    }
    else
    {
     //there were errors during the create call, go through the errors
     //array and write them to the screen
     for (int i=0;i<sr[j].getErrors().length;i++)
     {
      //get the next error
      com.sforce.soap.enterprise.Error err = sr[j].getErrors()[i];
      System.out.println("Errors were found on item " + new Integer(j).toString());
      System.out.println("Error code is: " + err.getStatusCode().toString());
      System.out.println("Error message: " + err.getMessage());
     }
    }
   }
  } catch (UnexpectedErrorFault uef) {
         System.out.println(uef.getExceptionMessage());
        } catch (Exception ex) {
   System.out.println("\nFailed to create account, error message was: \n" + ex.getMessage());
  }

 }

I also cut and pasted your code into my Eclipse project and it worked as well.  To find out the problem, we will need to inspect the soap message being generated from this call.  You can do this by running TCPMon which is included in the Axis libraries.  Create a new TCP/IP monitor and set the listen port # to 8082.  Select Act as a... Listener option.  Target hostname is na1-api.salesforce.com with a target port of 80.  Click the add button to create this listener.

In you login code, modify the part that recreates the binding with the new end point from:

  //set the session header for subsequent call authentication
  try {
   binding = (SoapBindingStub) new SforceServiceLocator().getSoap(new URL(loginResult.getServerUrl()));
  }
  catch (ServiceException jre)
  {
                  System.out.println(
                      "ERROR: creating binding to soap service, error was: \n" +
                      jre.getMessage());
                  return false;
                }
  catch (MalformedURLException e) {
   e.printStackTrace();
  }

TO:

  //set the session header for subsequent call authentication
  try {
   binding = (SoapBindingStub) new SforceServiceLocator().getSoap(new URL("http://localhost:8082services/Soap/c/2.5"));
  }
  catch (ServiceException jre)
  {
                  System.out.println(
                      "ERROR: creating binding to soap service, error was: \n" +
                      jre.getMessage());
                  return false;
                }
  catch (MalformedURLException e) {
   e.printStackTrace();
  }

Run you app and watch for the message that produces the error.

Copy the request and response and post them on this board.

-- Dave

DevAngelDevAngel

Hi AKR,

No that's enough.  I just wanted to aproximate your custom object as closely as possible.  And it looks like I have.

efantiniefantini

Hi,

I had exactly your problem with the same message.

The problem is:

Using your custom object obtained wlth wsdl2java with classes downloaded directly from sforce.

Stub classes downloaded doesn't support that object as an entity object.

The solution is to use the Class that create your custom object with classes compiled from the wsdl2java generated tree. Stub clusses generated from wsdl2java from your wsdl does support your custom object as entity object. 

Filippo