News, tips, tricks and discussions related to web strategy, web design, and custom web application and database development.
Viewing posts for topic: "Salesforce". View all posts.
This is a bare-bones, step-by-step guide for setting up a .NET MVC site to connect to the Salesforce API. Just the facts.
Get the Enterprise WSDL and Security Token
Login to a salesforce.com sandbox to begin. To get to the sandboxes for a live instance of Salesforce, go to the upper right hand and click on your name. Select "Setup" in the menu. Once there you can go to the lower left and click data management, and you will see sandbox listed under there. There is a login button to log in to the sandbox from there.
To generate the WSDL go to Setup => Develop => API => Generate Enterprise WSDL
Click the Generate button and save the resulting file to your computer.
To generate a security token go to Setup => My Personal Information => Reset My Security Token
Click on Reset Security Token to get a security token sent to your email address. You will need that later.
Set up the service reference
Add a service reference in Visual Studio. For the address, enter the path to the WSDL file you downloaded. For the namespace enter SalesforceService, or whatever makes sense for your project.
Binding and endpoint configuration information will be automatically added to your Web.config file.
Add settings in Web.config for the salesforce login. E.g.
<add key="SalesforceUsername" value="[email protected]" />
<add key="SalesforcePassword" value="Qal3jR......" />
The password is a combination of the password used to login to the site and the security token you got earlier.
Use transformations in your Web.Release.config file to set the endpoint and login for the live server.
Working with Salesforce
A small utility file, such as this example, makes working with Salesforce pretty easy.
For example, to create a lead:var sf = new SalesforceUtil();
sf.SaveLead(new Lead
{
FirstName = "Joe",
LastName = "Shmoe",
Email = "[email protected]
});
Error Workaround
You may get the following error when your site tries to connect to Salesforce (I did both times I set this up):
Unable to generate a temporary class (result=1).
error
CS0030: Cannot convert type
'MySite.SalesforceService.ListViewRecordColumn[]' to
'MySite.SalesforceService.ListViewRecordColumn'
...
The fix (which I found here: https://developer.salesforce.com/forums/?id=906F0000000Aj5kIAC) is pretty easy. In the auto-generated Reference.cs file for the service reference, search for this:
ListViewRecordColumn[][]
and replace it with this:
ListViewRecordColumn[]
More Documentation
SOAP API
https://developer.salesforce.com/docs/atlas.en-us.api.meta/api/sforce_api_quickstart_intro.htm
SOQL Queries
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/
Comments (0) Posted on February 25, 2016 10:03:40 AM EST by David Hammond