Systenics Solutions Logo
  • Home start here
  • Solutions services we provide
  • Products products we build
  • About Us who we are
  • Contact Us request a quote
  • Jobs work for us
  • Blog our views

Blog

Home / Blog

Integrate Salesforce with C# or ASP.NET MVC Application

  • by:
  • in:
  • tags: .NET, AuctionWorx, C-Sharp, Salesforce
  • 0 Comments

Introduction

This tutorial explains the manual steps to authenticate Salesforce account using C# or ASP.NET MVC application. Even though the sample provided is C# Console application, we have implemented the same with ASP.NET MVC application for RainWorx's AuctionWorx software.

Pre-requisites

1. Salesforce Test Account
2. Visual Studio (C#)

Manual Steps for SalesForce Registration

1.Let's start by creating a new project with name - "SalesForceAuthSample". Open Visual Studio, New Project -> Visual C# -> Windows -> Console Application

img1
Figure 1: Visual Studio > New Project

2. Create Salesforce test acccount.

3. Add references for "DeveloperForce.force" using NuGet Package Manager in your project.

4. For Salesforce Integration, we need following information such as Security Token, Consumer Key, Consumer Secret, Username, Password and IsSandBoxUser.

Security Token: We will get Security Token from the following location - Dropdown with Username located at top right corner > My Settings > Personal > Reset My Security Token. On clicking "Reset Security Token" button , the new Security Token will be sent on registered email address.

img1
Figure 2: Salesforce > Security Token

Consumer Key and Consumer Secret: We will get Consumer Key and Consumer Secret from the following location - Set Up > Create > App > New. Enter all required data. Callback URL is very important for authentication purpose and then Save it.

img1
Figure 3: Salesforce > Consumer Secret and Consumer Key

After saving the API, it will show page similar to screenshot given below.

img1
Figure 4: Salesforce > Apps

Click on Connected App Name and you will get Consumer Secret and Consumer Key.

img1
Figure 5: Salesforce > Connected App Details

Username and Password: The Username and Password will be your test Salesforce account login username and password.

IsSandBoxUser: In code given below, we will set this parameter to "true".

    
using Salesforce.Common;
using Salesforce.Force;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SalesForceAuthSample
{
    class Program
    {
        private static readonly string SecurityToken = System.Configuration.ConfigurationManager.AppSettings["SecurityToken"];
        private static readonly string ConsumerKey = System.Configuration.ConfigurationManager.AppSettings["ConsumerKey"];
        private static readonly string ConsumerSecret = System.Configuration.ConfigurationManager.AppSettings["ConsumerSecret"];
        private static readonly string Username = System.Configuration.ConfigurationManager.AppSettings["Username"];
        private static readonly string Password = System.Configuration.ConfigurationManager.AppSettings["Password"];
        private static readonly string IsSandboxUser = System.Configuration.ConfigurationManager.AppSettings["IsSandboxUser"];
       

        static void Main(string[] args)
        {
            try
            {
                var task = RunSample();
                task.Wait();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                var innerException = e.InnerException;
                while (innerException != null)
                {
                    Console.WriteLine(innerException.Message);
                    Console.WriteLine(innerException.StackTrace);
                    innerException = innerException.InnerException;
                }
            }
        }

      
        private static async Task RunSample()
        {
            try
            {
                var auth = new AuthenticationClient();
                // Authenticate with Salesforce
                Console.WriteLine("Authenticating with Salesforce");
                var url = IsSandboxUser.Equals("true", StringComparison.CurrentCultureIgnoreCase)
                    ? "https://login.salesforce.com/services/oauth2/token "
                    : "https://test.salesforce.com/services/oauth2/token";
                await auth.UsernamePasswordAsync(ConsumerKey, ConsumerSecret, Username, Password, url);
                Console.WriteLine("Connected to Salesforce");
                var client = new ForceClient(auth.InstanceUrl, auth.AccessToken, auth.ApiVersion);
                // retrieve all accounts
                Console.WriteLine("Get Accounts");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
            }
        }

    }
}

 

In next blog, I will explain about simple CRUD operations which we can perform on Salesforce.
Link - Salesforce CRUD operations using C# in AuctionWorx (ASP.NET MVC application)

Happy Coding :)

Share This Post:

About the Author

This post was written by on Tuesday December 15, 2015.

Related Posts
  • Salesforce CRUD operations using C# in AuctionWorx (ASP.NET MVC application) - 15 June 2016
comments powered by Disqus
Newer >
All Categories
  • Programming
  • General
  • DevOps
Tags
  • .NET (6)
  • Android (2)
  • ASP.NET 5 (1)
  • ASP.NET 6 (1)
  • asp.net core (1)
  • ASP.NET MVC (2)
  • AuctionWorx (2)
  • Build and Release (1)
  • CI (1)
  • Continuous Integration (1)
  • C-Sharp (7)
  • devops (1)
  • ExpressJS (1)
  • Linux (1)
  • Lucene (1)
  • NodeJS (1)
  • Phonegap (2)
  • Salesforce (2)
  • Socket.IO (1)
  • Umbraco 7 (1)
  • Visual Studio 2015 (1)
  • Visual Studio Online (1)
  • VMWare ESXI 6.0 (1)
  • Windows (2)

About Us

Systenics Solutions is a customized software development company. We specialize in building Cloud, Web, and Mobile based applications using the latest Cloud Technologies. Our fine-tuned agile processes help you smoothly progress from conceptualizing your ideas, building proto-types/wireframes to bringing your product to market, giving our clients complete visibility and control at all times. We strive to provide our global clients of various sizes with cost effective benefits of offshore development while providing expert technical services.


Microsoft Partner - Gold Cloud Platform

Contact Us

Systenics Solutions LLP

The Affaires, Unit #F-1, 1st Floor, Plot #9, Sector - 17, Opp. Bhumiraj Costarica, Sanpada, Navi Mumbai - 400705, India.

 

Telephone: +91-22-4825 0808

Email: info@systenics.com

Skype: saurabhn

GSTIN: 27AELFS2160N1ZJ

Testimonials

"Coming from a non-technical background, Saurabh and his team at Systenics took my business idea and turned it into a fully functional application which surpassed my expectations! You can be sure with them that all your IT related concerns will be covered."

Shobhan, CEO - IITJobs Inc

"The ability Systenics showed in code signing and deploying my click once code in Microsoft visual was truly awesome. I interviewed and tested 6 different development companies and only one was actually able to get the job done - that was Systenics Solutions! Professional, courteous and reliable - I highly recommend them and am very happy and eager to continue growing our business relationship now and in the near future. Thank you Saurabh"

Andre Pierre

I contracted with Systenics about 6 months ago, in an effort to customize auction software for a new company I am launching in the US. The entire process was as smooth as could be. Their estimate for the project was reasonable, and very close to the final number. I would absolutely use this company again, and I have so much confidence in their ability to work with me, I even agreed to a support agreement with them long term. Their ability to communicate with me in the US was always very timely. They listened to my thoughts and ideas, and then suggested some changes, that made my software have even greater value. I cannot thank them enough, and would highly suggest their quality services to anyone. A completely satisfied customer!

Joe Lefebvre - Pharmabid, LLC

Systenics did a great job on our customization , they clearly understood the requirements and completed the task in a timely manner. They were very thorough in project discussions and made sure that we understood how the customization works and suggested improvements when required

Mike Singh - Dr. Liquidator

Copyright © 2012-2024 Systenics Solutions LLP. All rights reserved.

BACK TO TOP