Repository navigation
Getting Started
The constructor of the SalesforceClient takes a SalesforceConfig object, and an optional boolean parameter which can be set to automatically log the client in upon instantiating.
SalesforceClient(SalesforceConfig config, bool login = false)Let's get started by setting up the configuration and Salesforce client:
public void Main()
{
var config = new SalesforceConfig
{
Environment = "", // Can be used to differentiate between multiple environments
Username = "salesforceUsername",
Password = "salesforcePassword",
SecurityToken = "securityToken",
IsSandbox = true
};
using (SalesforceClient client = new SalesforceClient(config))
{
// Salesforce logic
}
}If already connected to Salesforce using OAuth 2, you can just use the user's access_token and instance_url to build a session in the config.
var config = new SalesforceConfig
{
Session = new SalesforceSession
{
SessionId = accessToken, // "access_token" retrieved using OAuth 2
InstanceUrl = instanceUrl // "instance_url" retrieved with access token
}
};
using (var client = new SalesforceClient(config))
{
// Salesforce logic
}SalesforceMagic also provides the following Utility methods
This method can be used to retrieve the current session id.
string sessionId = client.GetSessionId();This method returns a SalesforceSession object
string sessionId = client.GetSessionId();
// returns
public class SalesforceSession
{
public string SessionId { get; set; }
public string InstanceUrl { get; set; }
public string Environment { get; set; }
public bool IsSandbox { get; set; }
public DateTime LastLogin { get; set; }
}SalesforceMagic gives you the ability to change the current environment of a particular client.
void ChangeEnvironment(SalesforceConfig config, bool login = false);We can use the session id if we want, but the method automatically uses the last session id retrieved as long as it is not stale.
Now let's set up the classes that we'll use to query/push data. Setting up DTOs