Friday, October 23, 2009

Finding an existing Salesforce Account using the S4S Data Connector

The following is an example of creating a new Salesforce Account from C# using the Sitecore for Salesforce Data Connector (DC).

using Microsoft.VisualStudio.TestTools.UnitTesting; //Only used for the Assert in the example
using FuseIT.Sitecore.SalesforceConnector.Entities;
using FuseIT.Sitecore.SalesforceConnector.Services;


public void CreateAccount()
    SalesforceSession salesforceSession = new SalesforceSession(
        new LoginDetails("", "salesforcePassword"));
    AccountService accountService = new AccountService(salesforceSession);
    string accountNameToFind = "FuseIT";
    Account matchingAccount = accountService.GetSingleByFieldEquals("Name", accountNameToFind);
    Assert.AreEqual(accountNameToFind, matchingAccount.Name);

For Salesforce Organizations with customizations, like fields, you would use the T4 generated classes that match your org rather than those in FuseIT.Sitecore.SalesforceConnector.Entities.
NB: These code snippets are applicable to the current 1.0.5 release.