
Salesforce Developer Environment Dotnet Tipsheet
DOWNLOAD
First things first !
To download this implementation guide, click the download button below.
If you need more information about the implementation guide, you can read the Table of Contents below.
SETTING UP YOUR NET DEVELOPER
ENVIRONMENT
Summary
Configure your local dev
environment for integrating
with Salesforce using NET
This tipsheet describes how to set up your local environment so that you can start using Salesforce APIs
such as SOAP API or REST API
Note If youre setting up a local environment to develop Salesforce applications using Apex and
custom Metadata API components take a look at the Salesforce Extensions for Visual Studio Code
This tipsheet focuses on tools and configurations youll need to set up your local development system It
assumes you already have a working Salesforce organization with the API Enabled permission API is
enabled by default on Developer Edition Enterprise Edition Unlimited Edition and Performance Edition
organizations
To create a Developer Edition org go to developersalesforcecomsignup and follow the
instructions for signing up for a Developer Edition organization
If you have a Salesforce organization you can use for development but need to set up a sandbox for
development and testing see Deploy Enhancements from Sandboxes in Salesforce Help
Installing Microsoft Visual Studio
Youll need to install Microsoft Visual Studio to use Salesforce APIs Visual Studio is a development
environment that enables you to create robust NET applications
To install Microsoft Visual Studio youll need a Windows system with Internet access Depending on your
system you might also need administratorlevel access to install Visual Studio
Microsoft Visual Studio provides the necessary development tools and SDKs that are required to build
Windows applications There are several versions and editions of Visual Studio each with different features
and different Windows platform requirements See
httpwwwvisualstudiocomproductscomparevisualstudioproductsvs to compare current editions
For this tip sheet we use Visual Studio Express for Windows on a Windows system
Navigate to httpwwwvisualstudiocomdownloadsdownloadvisualstudiovs in your browser
Follow the instructions to download the version of Visual Studio that fits your development needs
Doubleclick the installer executable and follow the steps to install Visual Studio
Picking a Path Based on Which API You Use
The next steps for setting up your development environment depend on which Salesforce API you want
to use
To use SOAP API CRUDbased Metadata API or any other WSDLbased Salesforce API complete the steps
in the following tasks
Download Developer WSDL Files WSDLBased APIs on page
Verify the WSDL Environment WSDLBased APIs on page
To use REST API Bulk API Connect REST API or any other RESTbased Salesforce APIs complete the steps
in the following tasks
Last updated November
Setting Up Your NET Developer Environment
Download Developer WSDL Files WSDLBased APIs
Setting Up Connected App Access RESTBased APIs on page
Verify the REST Environment RESTBased APIs on page
Tooling API provides SOAP and REST interfaces so depending on your needs you can set up your
environment by using one of the paths above
Download Developer WSDL Files WSDLBased APIs
Salesforce Web Services Definition Language WSDL files provide API details that you use in your developer
environment to make API calls
To download WSDL files directly from your Salesforce organization
Log in to your Salesforce developer organization in your browser
From Setup enter API in the Quick Find box then select API
Download the appropriate WSDL files for the API you want to use
a If you want to use SOAP API youll need either the Enterprise or Partner WSDL See Choosing a
WSDL in the SOAP API Developer Guide to determine which WSDL to download
b If you want to use Metadata API youll need the Metadata WSDL To login and authenticate with
Salesforce youll also need either the Enterprise or Partner WSDL
c If you want to use Tooling API youll need the Tooling WSDL To login and authenticate with
Salesforce youll also need either the Enterprise or Partner WSDL
Verify the WSDL Environment WSDLBased APIs
You can verify your developer environment with a simple C test application in Visual Studio
You should have Visual Studio installed and have the WSDL files that you need to use available Youll
need the Enterprise or Partner WSDL to follow the verification steps
Start Visual Studio
Click File New Project
In the New Project window navigate to Installed Templates Visual C Windows Select
Console Application
In the New Project window under Name name the project VerifyWSDLTest Under Solution
name name the solution VerifyWSDLTest Under Location pick a file location that youll
remember Click Ok A solution is created and Programcs is opened for editing
Click Project Add Service Reference
In the Add Service Reference window under Address enter the file URL path to your Enterprise or
Partner WSDL file For example if enterprisewsdl is saved in cwsdls enter
filecwsdlsenterprisewsdl Click Go The Services list is populated with an entry
that is named SforceService
Select SforceService Under Namespace enter sforce Your Add Service Reference window should
look something like the following image
Setting Up Your NET Developer Environment
Verify the WSDL Environment WSDLBased APIs
Click Ok The WSDL services are imported under the sforce namespace in your project
Replace the code in Programcs as described in the following section
Use the following simple login example code for your Programcs contents Replace YOUR DEVORG
USERNAME with your developer organization username and replace YOUR DEVORG PASSWORD
AND SECURITY TOKEN with your developer organization password appended with your security
token If you did not set a security token in your organization just provide your password A GitHub Gist
of this code is available here httpsgistgithubcomanonymousdcfbfb
using
using
using
using
using
using
using
System
SystemCollectionsGeneric
SystemLinq
SystemText
SystemThreadingTasks
SystemServiceModel
VerifyWSDLTestsforce
namespace VerifyWSDLTest
class Program
private static SoapClient client
private static LoginResult loginResult
private static bool login
client new SoapClient
string acctName YOUR DEVORG USERNAME
string acctPw YOUR DEVORG PASSWORD AND SECURITY TOKEN
Setting Up Your NET Developer Environment
Verify the WSDL Environment WSDLBased APIs
try
loginResult clientloginnull acctName acctPw
catch Exception e
ConsoleWriteLineUnexpected login error
eMessage
ConsoleWriteLineeStackTrace
return false
return true success
static void Mainstring args
if login
display some current login settings
ConsoleWriteService endpoint
loginResultserverUrl n
ConsoleWriteUsername
loginResultuserInfouserName n
ConsoleWriteSessionId loginResultsessionId
n
ConsoleWritePress any key to continuen
ConsoleReadKey
The following example output shows a typical successful run of this code
Service endpoint
httpsyourInstancesalesforcecomservicesSoapcDUTfDFUXpB
Username myUsermydeveditioncom
SessionId
DULfARoAQOYUBIRHntDOCfzESyoJJwHNovyYvIPTGjcvnC
Press any key to continue
If the verification project runs and displays output that matches your organization your developer
environment is set up and you can start developing NET applications that integrate with Salesforce If you
have additional WSDL files you can add them to your project via the Add Service Reference dialog as
described in steps and above
If you are using Microsoft Visual Studio or earlier in step Add Service Reference might be unavailable
Use Add Web Reference instead Under URL enter the file path to your WSDL such as
filecwsdlsenterprisewsdl Name the web reference sforce and click Add
Reference If you have to use a web reference use an instance of SforceService to call
SforceServicelogin instead of SoapClientlogin
Setting Up Your NET Developer Environment
Setting Up Connected App Access RESTBased APIs
Setting Up Connected App Access RESTBased APIs
Because Salesforce REST APIs use OAuth authentication create a connected app to integrate your
application with Salesforce
A connected app integrates an application with Salesforce using APIs Connected apps use standard SAML
and OAuth protocols to authenticate provide single signon and provide tokens for use with Salesforce
APIs In addition to standard OAuth capabilities connected apps allow Salesforce admins to set various
security policies and have explicit control over who can use the corresponding apps
Specify basic information about your app See Configure Basic Connected App Settings in Salesforce Help
Next provide OAuth settings See See Enable OAuth Settings for API Integration in Salesforce Help
For more information see Create a Connected App in Salesforce Help
Verify the REST Environment RESTBased APIs
You can verify your developer environment with a simple C test application in Visual Studio
You must have Visual Studio installed to create a C test application
Start Visual Studio
Click File New Project
In the New Project window navigate to Installed Templates Visual C Windows Select
Console Application
In the New Project window under Name name the project VerifyRESTTest Under Solution
name name the solution VerifyRESTTest Under Location pick a file location that youll
remember Click Ok A solution is created and Programcs is opened for editing
Click Project Add Reference
In the Reference Manager window navigate to Assemblies Framework Select
SystemRuntimeSerialization Ensure that the checkbox is selected and click Ok
Replace the code in Programcs as described in the following section
Use the following simple login example code for your Programcs file Replace YOUR DEVORG
USERNAME with your developer organization username and replace YOUR DEVORG PASSWORD
SECURITY TOKEN with your developer organization password appended with your security token
If you did not set a security token in your organization just provide your password Replace YOUR OAUTH
CONSUMER KEY with the consumer key from your development organizations connected app Replace
YOUR OAUTH CONSUMER SECRET with the consumer secret from your development organizations
connected app A GitHub Gist of this code is available here
httpsgistgithubcomanonymousdbeefaab
using
using
using
using
using
using
using
using
System
SystemCollectionsGeneric
SystemLinq
SystemText
SystemThreadingTasks
SystemNet
SystemRuntimeSerialization
SystemRuntimeSerializationJson
namespace VerifyRESTTest
Setting Up Your NET Developer Environment
Verify the REST Environment RESTBased APIs
class Program
Class used for serializing the OAuth JSON response
DataContract
public class OAuthUsernamePasswordResponse
DataMember
public string accesstoken get set
DataMember
public string id get set
DataMember
public string instanceurl get set
DataMember
public string issuedat get set
DataMember
public string signature get set
private static string accessToken
private static string instanceUrl
private static void login
string acctName YOUR DEVORG USERNAME
string acctPw YOUR DEVORG PASSWORD AND SECURITY TOKEN
string consumerKey YOUR OAUTH CONSUMER KEY
string consumerSecret YOUR OAUTH CONSUMER SECRET
Just for testing the developer environment we use the
simple usernamepassword OAuth flow
In production environments make sure to use a stronger
OAuth flow such as UserAgent
string strContent granttypepassword
clientid consumerKey
clientsecret consumerSecret
username acctName
password acctPw
string urlStr
httpsloginsalesforcecomservicesoauthtoken strContent
HttpWebRequest request WebRequestCreateurlStr as
HttpWebRequest
requestMethod POST
try
using HttpWebResponse response requestGetResponse
as HttpWebResponse
if responseStatusCode HttpStatusCodeOK
throw new ExceptionStringFormat
Setting Up Your NET Developer Environment
Verify the REST Environment RESTBased APIs
Server error HTTP
responseStatusCode
responseStatusDescription
Parse the JSON response and extract the access
token and instance URL
DataContractJsonSerializer jsonSerializer new
DataContractJsonSerializertypeofOAuthUsernamePasswordResponse
OAuthUsernamePasswordResponse objResponse
jsonSerializerReadObjectresponseGetResponseStream as
OAuthUsernamePasswordResponse
accessToken objResponseaccesstoken
instanceUrl objResponseinstanceurl
catch Exception e
ConsoleWriteLinenException Caught
ConsoleWriteLineMessage eMessage
static void Mainstring args
login
if accessToken
display some current login settings
ConsoleWriteInstance URL instanceUrl n
ConsoleWriteAccess Token accessToken n
ConsoleWritePress any key to continuen
ConsoleReadKey
The following example output shows a typical successful run of this code
Instance URL httpsyourInstancesalesforcecom
Access Token
DULfARoAQKlrimMZkhQpvHvVreCvYJafmsCdMgBMUltPflQ
Press any key to continue
If the verification C project runs and displays output that matches your organization your developer
environment is set up and you can start developing NET applications that integrate with Salesforce REST
APIs