Created
February 5, 2015 17:22
-
-
Save jeffdonthemic/955d621a46723dad30b6 to your computer and use it in GitHub Desktop.
Go-Force Snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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