Skip to content

Commit

Permalink
Merge pull request #179 from nicolasbock/query
Browse files Browse the repository at this point in the history
Add query option
  • Loading branch information
nicolasbock committed Sep 9, 2024
2 parents d83537b + 2c26678 commit 293aabf
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions cmd/salesforce-test/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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) {
Expand All @@ -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)
Expand Down

0 comments on commit 293aabf

Please sign in to comment.