diff --git a/cmd/salesforce-test/main.go b/cmd/salesforce-test/main.go index fe77ad6..38c65aa 100644 --- a/cmd/salesforce-test/main.go +++ b/cmd/salesforce-test/main.go @@ -23,6 +23,7 @@ var commentVisibility = kingpin.Flag("visibility", "Set the comment visibility { var getChatter = kingpin.Flag("chatter", "Get all chatter objects of case").Default("false").Bool() var getComments = kingpin.Flag("comments", "Get all comments of case").Default("false").Bool() var newChatter = kingpin.Flag("new-chatter", "Add a new chatter comment to the case").Default("").String() +var runQuery = kingpin.Flag("query", "Run query").Default("").String() func main() { log.Printf("Starting version %s", commit) @@ -73,6 +74,24 @@ func main() { newChatterComment(sfClient, caseId, *newChatter) } } + + if len(*runQuery) > 0 { + getQueryResult(sfClient, *runQuery) + } +} + +func getQueryResult(sfClient common.SalesforceClient, queryString string) { + log.Printf("Running query: '%s'", queryString) + records, err := sfClient.Query(queryString) + if err != nil { + log.Fatalf("Failed to run query: %v", err) + } + if len(records.Records) == 0 { + log.Fatal("Coudl not find any records") + } + for _, record := range records.Records { + log.Printf("%v", record) + } } func newChatterComment(sfClient common.SalesforceClient, caseId string, comment string) { @@ -96,6 +115,7 @@ func newChatterComment(sfClient common.SalesforceClient, caseId string, comment func getAllChatterComments(caseId string, sfClient common.SalesforceClient) { log.Print("Getting case chatter comments") query := fmt.Sprintf("SELECT Id, Body FROM FeedItem WHERE ParentID = '%s'", caseId) + log.Printf("Running query: '%s'", query) records, err := sfClient.Query(query) if err != nil { log.Fatalf("Failed to get chatter comments: %v", err)