Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I'll get my excuses in early: I'm a developer with some experience of working with APIs, but this is my first encounter with Salesforce.

We've been given a spec to interface with a customer's Salesforce implementation. The customer has given us some sample code, along with a WSDL file. We're trying to create a simple test application in C# (.Net 4.0) to mirror the sample code we've been given.

We can connect and authenticate to Salesforce (using the .login method) without any problems - we get a LoginResult back and everything looks fine. However, the sample we've been given has the following code:

SObject customer = new SObject();
customer.setType(“CustomerContact__c”);

We cannot find any object or class of the type SObject. There is sObject (lower case S), but this doesn't have a .setType method.

The sample code looks fairly simple, so I can't see what I'm doing wrong. Is SObject (rather than sObject) a typo in the sample code? Have we been given the wrong WSDL file? Or am I just missing something really obvious?

share|improve this question

3 Answers 3

up vote 4 down vote accepted

There is no method like setType in c#, instead use code below

sObject customer = new sObject();
customer.type = "CustomerContact__c";
share|improve this answer
    
Thanks - it seems the customer tried to hand-edit VB.Net code into what they thought was C# :/ All working now! –  KenD Feb 12 at 14:08

SObject Type

It looks like you have been given the Partner WSDL, this provides a generic "database like" API into Salesforce, so you need to use the SObject type which is a generic way of representing a record in Salesforce. Before you can send record data in this object it needs to know the actual object/table the record represents, hence the use of the 'type' property.

Partner vs Enterprise WSDL

From the looks of it, I'd say you've been given a Java sample not a C# one, in C# this is a property so is just assigned directly as in, customer.type. As regards what WSDL you really need that depends on if your developing code to work just against this customers Salesforce environment (they are not all the same) or any Salesforce customer environment. If its specific you might find using the Enterprise WSDL easier, as it generates types in the WSDL and thus in your C# code for each object and you don't have this abstraction to deal with. You can read me more about it here with some examples. The downside is the Enterprise WSDL can be quite large, as can the generated code.

New Salesforce Toolkits for .Net

However if your wanting to try something relatively new, Saleforce have now announced a supported .Net toolkit, Announcing the Salesforce Toolkits for .NET.

The Salesforce Toolkits for .NET provide native libraries for interacting with Salesforce APIs, including the REST API and Chatter API. These toolkits make it super simple to consume services from Salesforce within .NET applications by packaging them up as NuGet packages, thus handling deployment and versioning. These toolkits give .NET developers the ability to take their expertise and skills and apply it to a whole new set of applications that are built on Salesforce while also letting them integrate Salesforce better into their existing applications.

There is also a couple of good blog posts here on using it...

share|improve this answer

Welcome to Salesforce. SObject (captial S) is a legitimate Salesforce object, in this scenario it represents an abstraction of any Object you can have. (I believe it is talked about using the name "Standard Object").

What you are then doing with the instance method setType is giving that standard object a concrete type, in this case the object you are going for is a CustomerContact (and this is a custom object type as identified by the __c). You would be able to find this object type in your WSDL/Salesforce instance (Under Setup->Create->Objects)

Here are some examples of using SObject to create some records of different types in Apex with a partner WSDL: http://www.salesforce.com/us/developer/docs/api/Content/calls_and_the_partner_wsdl.htm

Is that of any use?

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.