3

Ok I have a really basic question. I'm am still very confused trying to use this platform. So I'm asking those types of questions that would not be well received on Stack Overflow. I want to become a productive member of this site, so please bear with me while I'm in the fog.

I have a VS C# console app, and I have used a connected service to link it with salesforce.

enter image description here

enter image description here

Now I am feeling like an absolute idiot, as I am not sure what I can do with that connection. I also have the added complication of not having a sandbox.

So my first question is:

  1. Do I need to use sandbox to develop my apps?

When I run the app I have this:

enter image description here

Now I'm wondering if I'm able to login to my salesforce account from the console line and access data. I just can't figure out how to make that connection. I understand that I can use an external database.. but I am assuming I can access the dummy data that salesforce supplies.

How can I actually access my salesforce data from the app?

I don't expect a detailed answer, just if someone is able to point me in the right direction. Salesforce has so many features, it's actually difficult for me to ascertain which ones I need to follow. Looking at this answer https://salesforce.stackexchange.com/a/7989/25387 I think I'm a 2.99 lol.

I'm mainly concerned with .net development and salesforce at this stage.

I added the VS to the title so not to be confused with salesforce console.
Thanks.

4
  • 1
    Have you reviewed : help.salesforce.com/apex/… - Connected Apps (the UI piece in SF, not the whole app) simply provide a means for authentication and access control. Once you are authenticated, you use the SOAP / REST api to access what you need in SF so review those docs.
    – Eric
    Commented Oct 14, 2015 at 22:45
  • 1
    There is the Salesforce CLI which allows you to connect to Salesforce from the command prompt. "Salesforce Trailhead" is a great place to learn general Salesforce. You don't need a sandbox but I would create a sandbox just in case you do something wrong! and doesnt take long to create. At least with a sandbox you know you can't break anything. You can go the oAuth route, depends what your app is doing. Have you seen: developer.salesforce.com/page/…
    – Francis
    Commented Oct 14, 2015 at 22:59
  • @Francis THANK YOU! I don't why I didn't find that, I've been scouring the site... it just takes time.. I need to upgrade my edition to get a sandbox.. Please feel free to draft your comment as a ans answer, as it's good.
    – user25387
    Commented Oct 14, 2015 at 23:52
  • @Eric yes I have seen that, but it wasn't gelling with me.. I think the other link is a good starting point and I've been listening to the pluralsight talks on .net, and doing some trailforce projects..++
    – user25387
    Commented Oct 14, 2015 at 23:55

1 Answer 1

3

After adding the Salesforce Connected Services to a .NET console application you have a couple of things:

  1. It will have brought in the Force.com .NET toolkit from nuget
  2. It will have created a Connected App for you in the org that you entered credentials for in the wizard.
  3. Optionally used T4 templates to generate entity classes for you in a Models folder.

To actually establish a Salesforce session in the console app you can use the AuthenticationClient. Sample based off the SimpleConsole application.

E.g.

    static void Main(string[] args)
    {
        var task = RunSample();
        task.Wait();

        Console.ReadLine();
    }

    private static async Task RunSample()
    {
        var auth = new AuthenticationClient();
        await auth.UsernamePasswordAsync(ConsumerKey, ConsumerSecret, Username, Password);
        Console.WriteLine("Connected to Salesforce");

        var client = new ForceClient(auth.InstanceUrl, auth.AccessToken, auth.ApiVersion);

        Console.WriteLine("Get Accounts");

        const string qry = "SELECT ID, Name FROM Account";
        var accts = new List<Account>();
        var results = await client.QueryAsync<Account>(qry);
        var totalSize = results.totalSize;

        Console.WriteLine("Queried " + totalSize + " records.");

        accts.AddRange(results.records);

    }

This excludes all sorts of error handling that you need, but it shows how to get connected and then make a basic SOQL query.

The ConsumerKey, ConsumerSecret, Username, and Password were all read from the App.config. The Consumer* fields you can get as per How to Get consumer Key and consumer Secret from Salesforce

You can make all your CRUD calls via the ForceClient class.

The example above was run against a developer edition org. The main difference with a sandbox would be changing the URL that AuthenticationClient uses.

1
  • 2
    I've CONNECTED!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! yeh :)
    – user25387
    Commented Oct 15, 2015 at 6:56

You must log in to answer this question.