Skip to content

Salesforce

Tim Hall edited this page Jun 10, 2013 · 3 revisions

An example of using Salesforce with Excel-REST is included in the examples/ folder of this project. Some details:

Authentication

  1. Use the instructions in Setup Salesforce to get a consumer key and secret
  2. Using the Username-Password OAuth Authentication Flow, use the OAuth2Authenticator and set it up as follows:
Dim Auth As New OAuth2Authenticator
Auth.Setup _
    ClientId:="ConsumerKey", _
    ClientSecret:="ConsumerSecret", _
    Username:="Username", _
    Password:="Password" & "SecurityToken"

Auth.SetupTokenUrl "https://login.salesforce.com/services/oauth2/token?grant_type=password"
Set pClient.Authenticator = Auth

Generic Object Request

Requests for objects (Accounts, Contacts, etc) pass through a general "sobjects" resource and therefore a generic object request can be created.

Public Function ObjectRequest(ObjectName As String, ObjectId As String) As RestRequest
    Dim Request As New RestRequest
    Request.Resource = "services/data/{ApiVersion}/sobjects/{ObjectName}/{ObjectId}"
    Request.AddUrlSegment "ApiVersion", "v26.0"
    Request.AddUrlSegment "ObjectName", ObjectName
    Request.AddUrlSegment "ObjectId", ObjectId
    Set ObjectRequest = Request
End Function

' e.g. Client.Execute(ObjectRequest("Account", "Id...12345"))

The example includes details on using async methods, updating objects, and setting up an simple implementation.

Clone this wiki locally