Query (SOQL)
Execute SOQL queries with pagination support and a fluent query builder.
Execute Query
Go
result, err := client.Query().Execute(ctx,
"SELECT Id, Name, Industry FROM Account WHERE Industry = 'Technology' LIMIT 10")
if err != nil {
log.Fatal(err)
}
fmt.Printf("Total: %d records\n", result.TotalSize)
for _, record := range result.Records {
fmt.Printf("%s - %s\n",
record.StringField("Name"),
record.StringField("Industry"))
}
Query Builder
Build queries programmatically with the fluent builder pattern:
Go
// Build a complex query
query := client.Query().NewBuilder("Contact").
Select("Id", "FirstName", "LastName", "Email").
WhereEquals("AccountId", accountID).
WhereNotNull("Email").
OrderByAsc("LastName").
Limit(50).
Build()
result, err := client.Query().Execute(ctx, query)
Query All Records
Automatically handle pagination to retrieve all records:
Go
// Fetch all records (handles pagination automatically)
allRecords, err := client.Query().ExecuteAllRecords(ctx,
"SELECT Id, Name FROM Account WHERE Industry = 'Technology'")
fmt.Printf("Total records: %d\n", len(allRecords))
Manual Pagination
Go
result, _ := client.Query().Execute(ctx, "SELECT Id FROM Account")
// Check if more records exist
for !result.Done {
// Process current batch
for _, r := range result.Records {
// process record
}
// Get next batch
result, _ = client.Query().QueryMore(ctx, result.NextRecordsURL)
}
Query with Callback
Go
// Process records in batches with a callback
err := client.Query().ExecuteWithCallback(ctx,
"SELECT Id, Name FROM Account",
func(records []types.Record) error {
for _, r := range records {
fmt.Println(r.StringField("Name"))
}
return nil
},
)
Builder Methods
| Method | Description |
|---|---|
Select(fields...) |
Fields to retrieve |
WhereEquals(field, value) |
Equality condition |
WhereIn(field, values) |
IN clause |
WhereLike(field, pattern) |
LIKE condition |
WhereNotNull(field) |
NOT NULL check |
WhereRaw(condition) |
Raw WHERE clause |
OrderByAsc(field) |
Ascending order |
OrderByDesc(field) |
Descending order |
Limit(n) |
Maximum records |
Offset(n) |
Skip records |