tags:

views:

156

answers:

2

I have an application that submits bugs for multiple customers to multiple destinations. I would like this application to include salesforce as a destination. I have web reference to the Enterprise WSDL and I am able to create cases for salesforce. This works great until I want to include user defined custom fields as part of the case. The custom fields are strongly typed with a __c prefix for my instance of salseforce. But I will not have the liberty of updating my web service with my customers instance of salesforce.

How can I submit a salesforce case with custom fields that are not defined in the WSDL?

Should I not be using the Enterprise WSDL?

+3  A: 

You need to use the Partner WSDL

It's loosely typed and so can be used with all 'orgs', whatever customisations they have.

Here's some Partner WSDL Examples in Java

codeulike
A: 

My code example using Partner WSDL

//Base class
public class SalesforceBase
{
    private readonly List<SalesforceCustomField> _customFields = new List<SalesforceCustomField>();
    private readonly XmlDocument _document = new XmlDocument();
    private readonly List<XmlElement> _elements = new List<XmlElement>();
    private readonly string _type;

    protected SalesforceBase(string type)
    {
        _type = type;
    }

    public string Type
    {
        get
        {
            return _type;
        }
    }

    public IEnumerable<SalesforceCustomField> CustomFields
    {
        get
        {
            return _customFields;
        }
    }

    public XmlElement[] Any
    {
        get
        {
            return _elements.ToArray();
        }
    }

    public void AddCustomField(SalesforceCustomField customField)
    {
        UpdateElements(customField.FieldName, customField.Value);
        _customFields.Add(customField);
    }

    protected void UpdateElements(string name, string value)
    {
        var element = _elements.Find(ele => ele.Name == name);
        if (element != null)
        {
            element.InnerText = value;
        }
        else
        {
            element = _document.CreateElement(name);
            element.InnerText = value;
            _elements.Add(element);
        }
    }
}
//Implement Base
public class SalesforceContact : SalesforceBase
{
    public SalesforceContact() : base("Contact") { }

    private string _firstName;
    public string FirstName
    {
        get { return _firstName; }
        set
        {
            if (value != null)
            {
                UpdateElements("FirstName", value);
                _firstName = value;
            }
        }
    }
}
//Send It
SForceService.create( new sObject(){Any = contact.Any, type = contact.Type});
Aaron

related questions