Skip to content

Instantly share code, notes, and snippets.

@jeffdonthemic
Created February 5, 2015 17:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffdonthemic/955d621a46723dad30b6 to your computer and use it in GitHub Desktop.
Save jeffdonthemic/955d621a46723dad30b6 to your computer and use it in GitHub Desktop.
Go-Force Snippets
package main
import (
"fmt"
"log"
"github.com/nimajalali/go-force/force"
"github.com/nimajalali/go-force/sobjects"
)
type SomeCustomSObject struct {
sobjects.BaseSObject
Id string `force:"Id"`
Name string `force:"Name"`
}
type AccountQueryResponse struct {
sobjects.BaseQuery
Records []sobjects.Account `json:"Records" force:"records"`
}
func (t *SomeCustomSObject) ApiName() string {
return "Account"
}
func main() {
// Init the force
forceApi, err := force.Create(
"v29.0",
"client-id",
"client-secret",
"username",
"password",
"security-token",
"production",
)
if err != nil {
log.Fatal(err)
}
//forceApi.Query("select id, name from account limit 2", out)
someCustomSObject := &SomeCustomSObject{}
err = forceApi.GetSObject("0017000000nV6aRAAS", someCustomSObject)
if err != nil {
fmt.Println(err)
}
fmt.Println("%#v", someCustomSObject.Name)
desc, err := forceApi.DescribeSObject(&sobjects.Account{})
if err != nil {
fmt.Println("Failed to retrieve description of sobject: %v", err)
}
fmt.Println(desc.AllFields)
list := &AccountQueryResponse{}
err = forceApi.Query("select id, name from account limit 2", list)
if err != nil {
fmt.Println("Failed to query: %v", err)
}
fmt.Println("%#v", list)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment