go-force
Note
Segment has paused maintenance on this project, but may return it to an active status in the future. Issues and pull requests from external contributors are not being considered, although internal contributions may appear from time to time. The project remains available under its open source license for anyone to use.
Golang API wrapper for Force.com, Salesforce.com
Installation
go get github.com/nimajalali/go-force/force
Example
package main
import (
"fmt"
"log"
"github.com/nimajalali/go-force/force"
"github.com/nimajalali/go-force/sobjects"
)
type SomeCustomSObject struct {
sobjects.BaseSObject
Active bool `force:"Active__c"`
AccountId string `force:"Account__c"`
}
func (t *SomeCustomSObject) ApiName() string {
return "SomeCustomObject__c"
}
type SomeCustomSObjectQueryResponse struct {
sobjects.BaseQuery
Records []*SomeCustomSObject `force:"records"`
}
func main() {
// Init the force
forceApi, err := force.Create(
"YOUR-API-VERSION",
"YOUR-CLIENT-ID",
"YOUR-CLIENT-SECRET",
"YOUR-USERNAME",
"YOUR-PASSWORD",
"YOUR-SECURITY-TOKEN",
"YOUR-ENVIRONMENT",
)
if err != nil {
log.Fatal(err)
}
// Get somCustomSObject by ID
someCustomSObject := &SomeCustomSObject{}
err = forceApi.GetSObject("Your-Object-ID", nil, someCustomSObject)
if err != nil {
fmt.Println(err)
}
fmt.Printf("%#v", someCustomSObject)
// Query
someCustomSObjects := &SomeCustomSObjectQueryResponse{}
err = forceApi.Query("SELECT Id FROM SomeCustomSObject__c LIMIT 10", someCustomSObjects)
if err != nil {
fmt.Println(err)
}
fmt.Printf("%#v", someCustomSObjects)
}
Documentation