Tuesday, 20 March 2007

Fun with the Salesforce API and custom fields

One of our marketing approaches is to offer a sms service trial of our Business SMS Service. This enables prospects to fully test the two-way SMS service before committing to one of our reasonably priced ;-) monthly plans.

We have recently adopted salesforce.com to improve our CRM and Sales processes and wanted to push all new trials into salesforce so our sales teams could follow them up.

We put together a simple application that utilises the salesforce web servce API to create Lead objects in salesforce and assign them to appropriate queues based on the prospects country. This was very simple and we were very quickly up and running but hit a stumbling block when we came to custom fields.

We've customised the Lead definition in our salesforce implementation to include URL fields that can link directly into our account management system. Making it very easy for the sales teams to manage the service features and promote the SMS service account when a customer decides to sign up.

The code samples for C# were a little sketchy when it came to custom fields. We spent a long time looking at blogs and forums trying to workout how to get these values pushed in. Then the lightbulb finally lit up.

Salesforce seems to have a generic datastore with loose descriptions of objects that contain collections of fields. The web service proxies that were supplied as part of the sample kit also all inheritied from sObject as below:

[System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:sobject.enterprise.soap.sforce.com")] public class Lead : sObject {

Upon further inspection, we discovered that XML serialisation attributes had been set on all fields in the Lead class, eg:

[System.Xml.Serialization.XmlElementAttribute(IsNullable=true)] public string Company;

Eureka! We just had to add additional fields for our custom fields and it worked, eg:

[System.Xml.Serialization.XmlElementAttribute(IsNullable = true)] public string AMS_Account_URL__c;

Note the field name is the API version of the field name. From within salesforce go to Setup > App Setup > Customize > Leads (or whichever object definition you want) > Fields and then click on the appropriate field to find this out.

So now whenever someone registers for a free trial of our Business SMS Service, salesforce is updated and we can assist them straight away.

No comments: