+ Start a Discussion
doubleminusdoubleminus 

Updating records problem - how to use correct package?

Hi,

 

I'm having a hard time using the api example (http://www.salesforce.com/us/developer/docs/api/index_Left.htm#StartTopic=Content%2Fsforce_api_calls_create_saveresult.htm|SkinName=webhelp) to update Cases. The code doesn't seem to be the problem...the problem is getting access to the appropriate classes for using the SaveResult[] type. See code below.

 

 

List<SObject> cases = query("Select Id FROM Case WHERE Custon_Number__c = '" + num + "'");
case_ID = cases.get(0).getId();

Case[] updates = new Case[1]; // above SOQL call should only retrieve 1 case
Case updateCase = new Case();
updateCase.setId(case_ID);
updateCase.setCurrent_Approver__C("John Doe");
updates[0] = updateCase;

// Invoke the update call and save the results
try {
SaveResult[] saveResults = binding.update(updates[0]); // ***HERE IS THE PROBLEM*** SaveResult[] cannot be resolved
}
catch (Exception ex) {
System.out.println("An unexpected error has occurred." + ex.getMessage());
return;
}

 

It looks like I need to use the com.salesforce.results package...(http://www.adnsandbox.com/media/flexsdk/docs/com/salesforce/results/package-detail.html)...but am unsure of how to do that. Any advice??

 

Also note, I'm using my own login and the enterprise.wsdl from a DE org where I have full admin permissions. Also, used latest 2.2.8 Apache CXF for wsdl2java, and all other parts of integration work fine.

 

SuperfellSuperfell

SaveResult should be generated from your from the WSDL, search the tree of files generated when you ran WSDL2Java.

doubleminusdoubleminus

I checked and SaveResultType.java is the closest. No SaveResult.java to be found. Is it because I used CXF?  I cannot get Axis 1.4 working at all (never have been able to).

 

And I just regenerated the files with CXF, using the -all argument this time, and tried the new classes. No luck. Same results.

doubleminusdoubleminus

Any ideas? Still struggling with this.

 

Thank you.

SuperfellSuperfell

Never used CXF. does the SaveResultType look like what you'd expect ? (success / id /errors  properties)

doubleminusdoubleminus

Yep, looks normal.

 

 

package com.sforce.soap.enterprise;

import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;


/**
 * <p>Java class for SaveResult complex type.
 * 
 * <p>The following schema fragment specifies the expected content contained within this class.
 * 
 * <pre>
 * &lt;complexType name="SaveResult">
 *   &lt;complexContent>
 *     &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 *       &lt;sequence>
 *         &lt;element name="errors" type="{urn:enterprise.soap.sforce.com}Error" maxOccurs="unbounded" minOccurs="0"/>
 *         &lt;element name="id" type="{urn:enterprise.soap.sforce.com}ID"/>
 *         &lt;element name="success" type="{http://www.w3.org/2001/XMLSchema}boolean"/>
 *       &lt;/sequence>
 *     &lt;/restriction>
 *   &lt;/complexContent>
 * &lt;/complexType>
 * </pre>
 * 
 * 
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "SaveResult", propOrder = {
    "errors",
    "id",
    "success"
})
public class SaveResultType {

    protected List<ErrorType> errors;
    @XmlElement(required = true, nillable = true)
    protected String id;
    protected boolean success;

    /**
     * Gets the value of the errors property.
     * 
     * <p>
     * This accessor method returns a reference to the live list,
     * not a snapshot. Therefore any modification you make to the
     * returned list will be present inside the JAXB object.
     * This is why there is not a <CODE>set</CODE> method for the errors property.
     * 
     * <p>
     * For example, to add a new item, do as follows:
     * <pre>
     *    getErrors().add(newItem);
     * </pre>
     * 
     * 
     * <p>
     * Objects of the following type(s) are allowed in the list
     * {@link ErrorType }
     * 
     * 
     */
    public List<ErrorType> getErrors() {
        if (errors == null) {
            errors = new ArrayList<ErrorType>();
        }
        return this.errors;
    }

    /**
     * Gets the value of the id property.
     * 
     * @return
     *     possible object is
     *     {@link String }
     *     
     */
    public String getId() {
        return id;
    }

    /**
     * Sets the value of the id property.
     * 
     * @param value
     *     allowed object is
     *     {@link String }
     *     
     */
    public void setId(String value) {
        this.id = value;
    }

    /**
     * Gets the value of the success property.
     * 
     */
    public boolean isSuccess() {
        return success;
    }

    /**
     * Sets the value of the success property.
     * 
     */
    public void setSuccess(boolean value) {
        this.success = value;
    }

}

 

 

SuperfellSuperfell

So use that one, CXF must do different schema type -> java type name mapping than Axis.

doubleminusdoubleminus

OK, I will use SaveResultType...

 

however, which library is the update method for Binding in?  update(new SObject[] {updateCase})

 

I cannot get this method working and none of the code samples show import statements. (http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_update.htm)

 

I imagine this Binding object is from the javax.xml.ws.Binding library. However, by default, that class has no update method.

 

Any idea?

SuperfellSuperfell

In axis its a class called SoapBindingStub. for your toolkit you'll have to read the docs on what class name is generated for the binding/operations defined in the WSDL.

doubleminusdoubleminus

Rats, no luck. I've dug through the documentation for CXF and have done about a hundred google searches to no avail. I just can't find anything similar. I really hope I won't have to redo things in Axis now - this is a fairly mature integration that has worked flawlessly for everything else. Arg, SOAP.

SuperfellSuperfell

You ought to be able to grep all the generated files to find it, look for the class that has all the login / create /update methods in it.