Skip to content

Commit

Permalink
Merge pull request #194 from nicolasbock/sf-test
Browse files Browse the repository at this point in the history
Slightly reword salesforce-test arguments
  • Loading branch information
nicolasbock authored Sep 12, 2024
2 parents 722da11 + 6d849a1 commit ae25957
Showing 1 changed file with 50 additions and 29 deletions.
79 changes: 50 additions & 29 deletions cmd/salesforce-test/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,19 @@ var configs = common.StringList(
var commit string

var (
allCases = kingpin.Flag("all-cases", "Get all cases").Default("false").Bool()
allFeedComments = kingpin.Flag("all-feed-comments", "Get all FeedComments").Default("false").Bool()
allFeedItems = kingpin.Flag("all-feed-items", "Get all FeedItems").Default("false").Bool()
addCaseFeed = kingpin.Flag("add-case-feed", "Add new CaseFeed object to case").Default("").String()
addFeedItem = kingpin.Flag("add-feed-item", "Add a new FeedItem object to the case").Default("").String()
allCase = kingpin.Flag("all-cases", "Get all Case objects").Default("false").Bool()
allCaseFeed = kingpin.Flag("all-case-feed", "Get all CaseFeed objects").Default("false").Bool()
allFeedComment = kingpin.Flag("all-feed-comments", "Get all FeedComment objects").Default("false").Bool()
allFeedItem = kingpin.Flag("all-feed-items", "Get all FeedItem objects").Default("false").Bool()
caseNumber = kingpin.Flag("case-id", "The case ID to query").Default("").String()
commentVisibility = kingpin.Flag("visibility", "Set the comment visibility {public, private)").Default("private").String()
describe = kingpin.Flag("describe", "Describe object").Default("").String()
describeGlobal = kingpin.Flag("describe-global", "Get the List of all available objects and their metadata for your organization's data").Default("false").Bool()
getCaseFeed = kingpin.Flag("case-feed", "Get all CaseFeed items from a case").Default("false").Bool()
getChatter = kingpin.Flag("chatter", "Get all chatter objects of case").Default("false").Bool()
getComments = kingpin.Flag("comments", "Get all comments of case").Default("false").Bool()
newCaseFeed = kingpin.Flag("new-case-feed", "Add new CaseFeed comment to case").Default("").String()
newChatter = kingpin.Flag("new-chatter", "Add a new chatter comment to the case").Default("").String()
getCaseComment = kingpin.Flag("case-comment", "Get all CaseComment objects of case").Default("false").Bool()
getCaseFeed = kingpin.Flag("case-feed", "Get all CaseFeed objects from a case").Default("false").Bool()
getFeedItem = kingpin.Flag("feed-item", "Get all FeedItem objects of case").Default("false").Bool()
runQuery = kingpin.Flag("query", "Run query").Default("").String()
)

Expand All @@ -56,18 +57,22 @@ func main() {
panic(err)
}

if *allCases {
if *allCase {
getAllCases(sfClient)
}

if *allFeedComments {
if *allFeedComment {
getAllFeedComments(sfClient)
}

if *allFeedItems {
if *allFeedItem {
getAllFeedItems(sfClient)
}

if *allCaseFeed {
getAllCaseFeed(sfClient)
}

if *describeGlobal {
getDescribeGlobal(sfClient)
}
Expand All @@ -78,24 +83,24 @@ func main() {

if len(*caseNumber) > 0 {
caseId := getCase(sfClient)
if *getComments {
getAllCaseComments(caseId, sfClient)
if *getCaseComment {
getCaseComments(caseId, sfClient)
}

if *getChatter {
getAllChatterComments(caseId, sfClient)
if *getFeedItem {
getFeedItems(caseId, sfClient)
}

if *getCaseFeed {
getAllCaseFeed(caseId, sfClient)
getCaseFeeds(caseId, sfClient)
}

if len(*newChatter) > 0 {
newChatterComment(sfClient, caseId, *newChatter)
if len(*addFeedItem) > 0 {
newFeedItem(sfClient, caseId, *addFeedItem)
}

if len(*newCaseFeed) > 0 {
newCaseFeedComment(sfClient, caseId, *newCaseFeed)
if len(*addCaseFeed) > 0 {
newCaseFeed(sfClient, caseId, *addCaseFeed)
}
}

Expand All @@ -118,8 +123,8 @@ func getQueryResult(sfClient common.SalesforceClient, queryString string) {
}
}

func newChatterComment(sfClient common.SalesforceClient, caseId string, comment string) {
log.Print("Added new chatter comment")
func newFeedItem(sfClient common.SalesforceClient, caseId string, comment string) {
log.Print("Added new FeedItem object to case")
visibility := ""
switch *commentVisibility {
case "public":
Expand All @@ -136,8 +141,8 @@ func newChatterComment(sfClient common.SalesforceClient, caseId string, comment
Create()
}

func newCaseFeedComment(sfClient common.SalesforceClient, caseId string, comment string) {
log.Printf("Added new chatter (CaseFeed) comment for Id %s", caseId)
func newCaseFeed(sfClient common.SalesforceClient, caseId string, comment string) {
log.Printf("Added new CaseFeed object to case %s", caseId)
visibility := ""
switch *commentVisibility {
case "public":
Expand All @@ -154,8 +159,8 @@ func newCaseFeedComment(sfClient common.SalesforceClient, caseId string, comment
Create()
}

func getAllChatterComments(caseId string, sfClient common.SalesforceClient) {
log.Print("Getting case chatter comments")
func getFeedItems(caseId string, sfClient common.SalesforceClient) {
log.Print("Getting all FeedItem objects for case")
query := fmt.Sprintf("SELECT Id, Body FROM FeedItem WHERE ParentID = '%s'", caseId)
log.Printf("Running query: '%s'", query)
records, err := sfClient.Query(query)
Expand All @@ -169,8 +174,9 @@ func getAllChatterComments(caseId string, sfClient common.SalesforceClient) {
log.Printf("%s: %s", comment["Id"], comment["Body"])
}
}
func getAllCaseFeed(caseId string, sfClient common.SalesforceClient) {
log.Print("Getting case feed chatter comments")

func getCaseFeeds(caseId string, sfClient common.SalesforceClient) {
log.Print("Getting all CaseFeed objects for case")
query := fmt.Sprintf("SELECT Id, Body FROM CaseFeed WHERE ParentID = '%s'", caseId)
log.Printf("Running query: '%s'", query)
records, err := sfClient.Query(query)
Expand All @@ -187,7 +193,7 @@ func getAllCaseFeed(caseId string, sfClient common.SalesforceClient) {
}
}

func getAllCaseComments(caseId string, sfClient common.SalesforceClient) {
func getCaseComments(caseId string, sfClient common.SalesforceClient) {
log.Print("Getting case comments")
query := fmt.Sprintf("SELECT Id, CommentBody FROM CaseComment WHERE ParentId = '%s'", caseId)
records, err := sfClient.Query(query)
Expand Down Expand Up @@ -234,6 +240,21 @@ func getAllFeedItems(sfClient common.SalesforceClient) {
}
}

func getAllCaseFeed(sfClient common.SalesforceClient) {
log.Println("All CaseFeed:")
records, err := sfClient.Query("SELECT Id, Body, ParentId from CaseFeed")
if err != nil {
log.Fatalln("Failed to query for all CaseFeed")
}
for _, result := range records.Records {
if result["Body"] != nil {
log.Printf("%s (%s): %s", result["Id"], result["ParentId"], result["Body"])
} else {
log.Printf("%s (%s): empty body", result["Id"], result["ParentId"])
}
}
}

func getDescribeGlobal(sfClient common.SalesforceClient) {
log.Println("Getting all available global objects")
describeResult, err := sfClient.DescribeGlobal()
Expand Down

0 comments on commit ae25957

Please sign in to comment.