forked from simpleforce/simpleforce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tooling.go
55 lines (46 loc) · 1.48 KB
/
tooling.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package simpleforce
import (
"encoding/json"
"fmt"
"log"
"net/url"
)
// ExecuteAnonymousResult is returned by ExecuteAnonymous function
type ExecuteAnonymousResult struct {
Line int `json:"line"`
Column int `json:"column"`
Compiled bool `json:"compiled"`
Success bool `json:"success"`
CompileProblem interface{} `json:"compileProblem"`
ExceptionStackTrace interface{} `json:"exceptionStackTrace"`
ExceptionMessage interface{} `json:"exceptionMessage"`
}
// Tooling is called to specify Tooling API, e.g. client.Tooling().Query(q)
func (client *Client) Tooling() *Client {
client.useToolingAPI = true
return client
}
func (client *Client) UnTooling() {
client.useToolingAPI = false
}
// ExecuteAnonymous executes a body of Apex code
func (client *Client) ExecuteAnonymous(apexBody string) (*ExecuteAnonymousResult, error) {
if !client.isLoggedIn() {
return nil, ErrAuthentication
}
// Create the endpoint
formatString := "%s/services/data/v%s/tooling/executeAnonymous/?anonymousBody=%s"
baseURL := client.instanceURL
endpoint := fmt.Sprintf(formatString, baseURL, client.apiVersion, url.QueryEscape(apexBody))
data, err := client.httpRequest("GET", endpoint, nil)
if err != nil {
log.Println(logPrefix, "HTTP GET request failed:", endpoint)
return nil, err
}
var result ExecuteAnonymousResult
err = json.Unmarshal(data, &result)
if err != nil {
return nil, err
}
return &result, nil
}