Tooling API
Access Salesforce Tooling API for Apex development, testing, and metadata.
Execute Anonymous Apex
Go
result, err := client.Tooling().ExecuteAnonymous(ctx, `
System.debug('Hello from Go SDK!');
Account acc = new Account(Name = 'Test');
insert acc;
`)
if result.Success {
fmt.Println("Execution successful")
} else {
fmt.Println("Error:", result.CompileProblem)
}
Run Tests Asynchronously
Go
testRunId, err := client.Tooling().RunTestsAsync(ctx, tooling.TestRequest{
ClassIds: []string{classId1, classId2},
})
// Check test status
status, _ := client.Tooling().GetTestRunStatus(ctx, testRunId)
Query Tooling Objects
Go
// Query Apex classes
result, _ := client.Tooling().Query(ctx,
"SELECT Id, Name, Body FROM ApexClass LIMIT 10")
// Query Apex triggers
triggers, _ := client.Tooling().Query(ctx,
"SELECT Id, Name FROM ApexTrigger WHERE Status = 'Active'")
Get Debug Logs
Go
logs, _ := client.Tooling().GetApexLogs(ctx, 10)
for _, log := range logs {
fmt.Printf("%s: %d bytes\n", log.Operation, log.LogLength)
}
// Get log body
body, _ := client.Tooling().GetLogBody(ctx, logId)
Available Methods
| Method | Description |
|---|---|
Query() |
Query tooling objects |
ExecuteAnonymous() |
Execute anonymous Apex |
RunTestsAsync() |
Run unit tests async |
GetTestRunStatus() |
Get test run status |
GetApexLogs() |
List debug logs |
GetLogBody() |
Get log content |
GetCodeCompletion() |
Get Apex completions |
CreateApexClass() |
Create Apex class |