From b923c4a91b37d1428892dda780e5673d872769da Mon Sep 17 00:00:00 2001 From: g8rswimmer <34941871+g8rswimmer@users.noreply.github.com> Date: Thu, 9 May 2019 20:12:09 -0700 Subject: [PATCH] Documentation updates (#29) * added readme * added the readme * corrected link * using tabs * Updating readme file * updated * updated the readme * Took out the println --- README.md | 13 ++ composite/README.md | 10 +- composite/batch/README.md | 71 ++++++++ credentials/README.md | 16 +- session/README.md | 21 ++- sobject/README.md | 160 +++++++---------- sobject/collections/README.md | 321 +++++++++++++++++----------------- sobject/tree/README.md | 157 ++++++++--------- soql/README.md | 28 +-- 9 files changed, 418 insertions(+), 379 deletions(-) create mode 100644 composite/batch/README.md diff --git a/README.md b/README.md index d24bc89..9bcd2e7 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,14 @@ # go-sfdc This is a `golang` library for interfacing with `Salesforce` APIs. +## Getting Started +### Installing +To start using GO-SFDC, install GO and run `go get` +``` +go get -u github.com/g8rswimmer/go-sfdc +``` +This will retrieve the library. + ## Usage To use this library, the following will need to be done. * Create `Salesforce` [credentials](./credentials/README.md) to properly authenticate with the `Salesforce org` @@ -11,6 +19,8 @@ To use this library, the following will need to be done. - [SObject Collection APIs](./sobject/collections/README.md) - [SObject Tree API](./sobject/tree/README.md) - [SOQL APIs](./soql/README.md) + - [Composite](./composite/README.md) + - [Composite Batch](./composite/batch/README.md) ## Configuration The configuration defines several parameters that can be used by the library. The configuration is used per [session](./session/README.md). @@ -25,3 +35,6 @@ config := sfdc.Configuration{ Version: 44, } ``` + +## License +GO-SFDC source code is available under the [MIT License](LICENSE.txt) \ No newline at end of file diff --git a/composite/README.md b/composite/README.md index 628ee9e..cd275fc 100644 --- a/composite/README.md +++ b/composite/README.md @@ -1,7 +1,7 @@ # Composite API [back](../README.md) -The `sobject` package is an implementation of `Salesforce APIs` centered on `Composite` operations. These operations include: +The `composite` package is an implementation of `Salesforce APIs` centered on `Composite` operations. These operations include: * SObject Resources * Query Resource * Query All Resource @@ -81,16 +81,14 @@ func (c *compositeSubRequest) Body() map[string]interface{} { resource, err := composite.NewResource(session) if err != nil { - fmt.Printf("Composite Error %s", err.Error()) - fmt.Println() + fmt.Printf("Composite Error %s\n", err.Error()) return } value, err := resource.Retrieve(false, subRequests) if err != nil { - fmt.Printf("Composite Error %s", err.Error()) - fmt.Println() + fmt.Printf("Composite Error %s\n", err.Error()) return } - fmt.Printf("%+v", value) + fmt.Printf("%+v\n", value) ``` diff --git a/composite/batch/README.md b/composite/batch/README.md new file mode 100644 index 0000000..f83ddc5 --- /dev/null +++ b/composite/batch/README.md @@ -0,0 +1,71 @@ +# Composite Batch API +[back](../../README.md) + +The `batch` package is an implementation of `Salesforce APIs` centered on `Composite Batch` operations. These operations include: +* Limits Resources +* SObject Resources +* Query All +* Query +* Search +* Connect Resources +* Chatter Resources + +As a reference, see `Salesforce API` [documentation](https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/intro_what_is_rest_api.htm) + +## Examples +The following are examples to access the `APIs`. It is assumed that a `sfdc` [session](../../session/README.md) has been created. +### Subrequest +```go +type batchSubrequester struct { + url string + method string + richInput map[string]interface{} + binaryPartName string + binaryPartAlais string +} + +func (b *batchSubrequester) URL() string { + return b.url +} +func (b *batchSubrequester) Method() string { + return b.method +} +func (b *batchSubrequester) BinaryPartName() string { + return b.binaryPartName +} +func (b *batchSubrequester) BinaryPartNameAlias() string { + return b.binaryPartAlais +} +func (b *batchSubrequester) RichInput() map[string]interface{} { + return b.richInput +} +``` +### Composite Batch +```go + subRequests := []batch.Subrequester{ + &batchSubrequester{ + url: "v44.0/sobjects/Account/0012E00001qLpKZQA0", + method: http.MethodPatch, + richInput: map[string]interface{}{ + "Name": "NewName", + }, + }, + &batchSubrequester{ + url: "v44.0/sobjects/Account/0012E00001qLpKZQA0", + method: http.MethodGet, + }, + } + + resource, err := batch.NewResource(session) + if err != nil { + fmt.Printf("Batch Composite Error %s\n", err.Error()) + return + } + value, err := resource.Retrieve(false, subRequests) + if err != nil { + fmt.Printf("Batch Composite Error %s\n", err.Error()) + return + } + + fmt.Printf("%+v\n", value) +``` diff --git a/credentials/README.md b/credentials/README.md index 079deab..b5d28f6 100644 --- a/credentials/README.md +++ b/credentials/README.md @@ -11,16 +11,16 @@ The following are some example(s) of creating credentials to be used when openin ### Password ```go creds := credentials.PasswordCredentails{ - URL: "https://login.salesforce.com", - Username: "my.user@name.com", - Password: "greatpassword", - ClientID: "asdfnapodfnavppe", - ClientSecret: "12312573857105", + URL: "https://login.salesforce.com", + Username: "my.user@name.com", + Password: "greatpassword", + ClientID: "asdfnapodfnavppe", + ClientSecret: "12312573857105", } config := sfdc.Configuration{ - Credentials: credentials.NewPasswordCredentials(creds), - Client: salesforceHTTPClient, - Version: 44, + Credentials: credentials.NewPasswordCredentials(creds), + Client: salesforceHTTPClient, + Version: 44, } ``` diff --git a/session/README.md b/session/README.md index e556bbd..47c598a 100644 --- a/session/README.md +++ b/session/README.md @@ -7,25 +7,24 @@ The session is used to authenticate with `Salesforce` and retrieve the org's inf The following example demonstrates how to create a session. ```go creds := credentials.PasswordCredentails{ - URL: "https://login.salesforce.com", - Username: "my.user@name.com", - Password: "greatpassword", - ClientID: "asdfnapodfnavppe", - ClientSecret: "12312573857105", + URL: "https://login.salesforce.com", + Username: "my.user@name.com", + Password: "greatpassword", + ClientID: "asdfnapodfnavppe", + ClientSecret: "12312573857105", } config := sfdc.Configuration{ - Credentials: credentials.NewPasswordCredentials(creds), - Client: http.DefaultClient, - Version: 44, + Credentials: credentials.NewPasswordCredentials(creds), + Client: http.DefaultClient, + Version: 44, } session, err := session.Open(config) if err != nil { - fmt.Printf("Error %s", err.Error()) - fmt.Println() - return + fmt.Printf("Error %s\n", err.Error()) + return } // access Salesforce APIs diff --git a/sobject/README.md b/sobject/README.md index 056f534..70771b3 100644 --- a/sobject/README.md +++ b/sobject/README.md @@ -28,15 +28,13 @@ sobjResources := sobject.NewResources(session) metadata, err := sobjResources.Metadata("Account") if err != nil { - fmt.Printf("Error %s", err.Error()) - fmt.Println() - return + fmt.Printf("Error %s\n", err.Error()) + return } fmt.Println("Account Metadata") fmt.Println("-------------------") fmt.Printf("%+v\n", metadata) -fmt.Println() ``` ### Describe ```go @@ -45,15 +43,13 @@ sobjResources := sobject.NewResources(session) describe, err := sobjResources.Describe("Account") if err != nil { - fmt.Printf("Error %s", err.Error()) - fmt.Println() - return + fmt.Printf("Error %s\n", err.Error()) + return } fmt.Println("Account Describe") fmt.Println("-------------------") fmt.Printf("%+v\n", describe) -fmt.Println() ``` ### DML Insert ```go @@ -73,34 +69,32 @@ func (d *dml) Fields() map[string]interface{} { sobjResources := sobject.NewResources(session) dml := &dml{ - sobject: "Account", - fields: map[string]interface{}{ - "Name": "Test Account", - "MyUID__c": "AccExID222", - "MyCustomText__c": "My fun text", - "Phone": "9045551212", - }, + sobject: "Account", + fields: map[string]interface{}{ + "Name": "Test Account", + "MyUID__c": "AccExID222", + "MyCustomText__c": "My fun text", + "Phone": "9045551212", + }, } insertValue, err := sobjResources.Insert(dml) if err != nil { - fmt.Printf("Insert Error %s", err.Error()) - fmt.Println() - return + fmt.Printf("Insert Error %s\n", err.Error()) + return } fmt.Println("Account") fmt.Println("-------------------") fmt.Printf("%+v\n", insertValue) -fmt.Println() ``` ### DML Update ```go type dml struct { sobject string fields map[string]interface{} - id string + id string } func (d *dml) SObject() string { @@ -117,7 +111,7 @@ func (d *dml) ID() string { sobjResources := sobject.NewResources(session) dml := &dml{ - sobject: "Account", + sobject: "Account", } dml.id = "Account Salesforce ID" @@ -127,14 +121,13 @@ dml.fields["MyCustomText__c"] = "updated text" err = sobjResources.Update(dml) if err != nil { - fmt.Printf("Update Error %s", err.Error()) - fmt.Println() - return + fmt.Printf("Update Error %s\n", err.Error()) + fmt.Println() + return } fmt.Println("Account Updated") fmt.Println("-------------------") -fmt.Println() ``` ### DML Upsert @@ -162,7 +155,7 @@ func (d *dml) ExternalField() string { sobjResources := sobject.NewResources(session) dml := &dml{ - sobject: "Account", + sobject: "Account", } dml.id = "AccExID345" dml.externalField = "MyUID__c" @@ -171,15 +164,13 @@ dml.fields["Name"] = "Upsert Update" upsertValue, err := sobjResources.Upsert(dml) if err != nil { - fmt.Printf("Upsert Error %s", err.Error()) - fmt.Println() - return + fmt.Printf("Upsert Error %s\n", err.Error()) + return } fmt.Println("Account Upsert") fmt.Println("-------------------") fmt.Printf("%+v\n", upsertValue) -fmt.Println() ``` ### DML Delete ```go @@ -198,16 +189,15 @@ func (d *dml) ID() string { sobjResources := sobject.NewResources(session) dml := &dml{ - sobject: "Account", - id: "0012E00001oHQDNQA4", + sobject: "Account", + id: "0012E00001oHQDNQA4", } err = sobjResources.Delete(dml) if err != nil { - fmt.Printf("Upsert Error %s", err.Error()) - fmt.Println() - return + fmt.Printf("Upsert Error %s\n", err.Error()) + return } fmt.Println("Account Deleted") @@ -235,21 +225,19 @@ func (q *query) Fields() []string { sobjResources := sobject.NewResources(session) query := &query{ - sobject: "Account", - id: "Account Salesforce ID", + sobject: "Account", + id: "Account Salesforce ID", } record, err := sobjResources.Query(query) if err != nil { - fmt.Printf("Query Error %s", err.Error()) - fmt.Println() - return + fmt.Printf("Query Error %s\n", err.Error()) + return } fmt.Println("Account Query") fmt.Println("-------------------") -fmt.Printf("%+v", record) -fmt.Println() +fmt.Printf("%+v\n", record) ``` Return specific `SObject` fields. @@ -273,27 +261,25 @@ func (q *query) Fields() []string { sobjResources := sobject.NewResources(session) query := &query{ - sobject: "Account", - id: "Account Salesforce ID", - fields: []string{ - "Name", - "MyUID__c", - "Phone", - "MyCustomText__c", - }, + sobject: "Account", + id: "Account Salesforce ID", + fields: []string{ + "Name", + "MyUID__c", + "Phone", + "MyCustomText__c", + }, } record, err := sobjResources.Query(query) if err != nil { - fmt.Printf("Query Error %s", err.Error()) - fmt.Println() - return + fmt.Printf("Query Error %s\n", err.Error()) + return } fmt.Println("Account Query") fmt.Println("-------------------") -fmt.Printf("%+v", record) -fmt.Println() +fmt.Printf("%+\nv", record) ``` ### Query: With External ID @@ -322,22 +308,20 @@ func (q *query) ExternalField() string { sobjResources := sobject.NewResources(session) query := &query{ - sobject: "Account", - id: "AccExID234", - external: "MyUID__c", + sobject: "Account", + id: "AccExID234", + external: "MyUID__c", } record, err := sobjResources.ExternalQuery(query) if err != nil { - fmt.Printf("Query Error %s", err.Error()) - fmt.Println() - return + fmt.Printf("Query Error %s\n", err.Error()) + return } fmt.Println("Account Query") fmt.Println("-------------------") -fmt.Printf("%+v", record) -fmt.Println() +fmt.Printf("%+v\n", record) ``` Return specific `SObject` fields. ```go @@ -364,27 +348,25 @@ func (q *query) ExternalField() string { sobjResources := sobject.NewResources(session) query := &query{ - sobject: "Account", - id: "AccExID234", - external: "MyUID__c", - fields: []string{ - "Name", - "Phone", - "MyCustomText__c", - }, + sobject: "Account", + id: "AccExID234", + external: "MyUID__c", + fields: []string{ + "Name", + "Phone", + "MyCustomText__c", + }, } record, err := sobjResources.ExternalQuery(query) if err != nil { - fmt.Printf("Query Error %s", err.Error()) - fmt.Println() - return + fmt.Printf("Query Error %s\n", err.Error()) + return } fmt.Println("Account Query") fmt.Println("-------------------") -fmt.Printf("%+v", record) -fmt.Println() +fmt.Printf("%+v\n", record) ``` ### List of Deleted Records ```go @@ -392,15 +374,13 @@ sobjResources := sobject.NewResources(session) deletedRecords, err := sobjResources.DeletedRecords("Account", time.Now().Add(time.Hour*-12), time.Now()) if err != nil { - fmt.Printf("Deleted Records Error %s", err.Error()) - fmt.Println() - return + fmt.Printf("Deleted Records Error %s\n", err.Error()) + return } fmt.Println("Deleted Account Records") fmt.Println("-------------------") -fmt.Printf("%+v", deletedRecords) -fmt.Println() +fmt.Printf("%+v\n", deletedRecords) ``` ### List of Updated Records ```go @@ -408,15 +388,13 @@ sobjResources := sobject.NewResources(session) updatedRecords, err := sobjResources.UpdatedRecords("Account", time.Now().Add(time.Hour*-12), time.Now()) if err != nil { - fmt.Printf("Deleted Records Error %s", err.Error()) - fmt.Println() - return + fmt.Printf("Deleted Records Error %s\n", err.Error()) + return } fmt.Println("Updated Account Records") fmt.Println("-------------------") -fmt.Printf("%+v", updatedRecords) -fmt.Println() +fmt.Printf("%+v\n", updatedRecords) ``` ### Get Attachment and Document Content @@ -425,15 +403,13 @@ sobjResources := sobject.NewResources(session) attachment, err := sobjResources.GetContent("Attachment ID", sobject.AttachmentType) if err != nil { - fmt.Printf("Error %s", err.Error()) - fmt.Println() - return + fmt.Printf("Error %s\n", err.Error()) + return } document, err := sobjResources.GetContent("Document ID", sobject.DocumentType) if err != nil { - fmt.Printf("Error %s", err.Error()) - fmt.Println() - return + fmt.Printf("Error %s\n", err.Error()) + return } ``` diff --git a/sobject/collections/README.md b/sobject/collections/README.md index e5c7a8f..eb0f472 100644 --- a/sobject/collections/README.md +++ b/sobject/collections/README.md @@ -47,178 +47,175 @@ func (q *query) Fields() []string { ``` ### Create Multiple Records ```go - // insert some records - var insertRecords []sobject.Inserter - - acc1 := &dml{ - sobject: "Account", - fields: map[string]interface{}{ - "Name": "Collections Demo", - "Phone": "9045551212", - }, - } - insertRecords = append(insertRecords, acc1) - acc2 := &dml{ - sobject: "Account", - fields: map[string]interface{}{ - "Name": "Collections Demo Two", - "Active__c": "Yes", - }, - } - insertRecords = append(insertRecords, acc2) - con1 := &dml{ - sobject: "Contact", - fields: map[string]interface{}{ - "LastName": "Last Name Demo", - "AssistantPhone": "6065551212", - }, - } - insertRecords = append(insertRecords, con1) - con2 := &dml{ - sobject: "Contact", - fields: map[string]interface{}{ - "LastName": "Last Name Demo Two", - "Level__c": "Tertiary", - }, - } - insertRecords = append(insertRecords, con2) - - resource := collections.NewResources(session) - values, err := resource.Insert(true, insertRecords) - if err != nil { - fmt.Printf("Collection Error %s", err.Error()) - fmt.Println() - return - } - - fmt.Println("Collections Inserted") - fmt.Println("-------------------") - for _, value := range values { - fmt.Printf("%+v\n", value) - } - fmt.Println() +// insert some records +var insertRecords []sobject.Inserter + +acc1 := &dml{ + sobject: "Account", + fields: map[string]interface{}{ + "Name": "Collections Demo", + "Phone": "9045551212", + }, +} +insertRecords = append(insertRecords, acc1) +acc2 := &dml{ + sobject: "Account", + fields: map[string]interface{}{ + "Name": "Collections Demo Two", + "Active__c": "Yes", + }, +} +insertRecords = append(insertRecords, acc2) +con1 := &dml{ + sobject: "Contact", + fields: map[string]interface{}{ + "LastName": "Last Name Demo", + "AssistantPhone": "6065551212", + }, +} +insertRecords = append(insertRecords, con1) +con2 := &dml{ + sobject: "Contact", + fields: map[string]interface{}{ + "LastName": "Last Name Demo Two", + "Level__c": "Tertiary", + }, +} +insertRecords = append(insertRecords, con2) + +resource := collections.NewResources(session) +values, err := resource.Insert(true, insertRecords) +if err != nil { + fmt.Printf("Collection Error %s\n", err.Error()) + return +} + +fmt.Println("Collections Inserted") +fmt.Println("-------------------") +for _, value := range values { + fmt.Printf("%+v\n", value) +} +fmt.Println() ``` ### Update Multiple Records ```go - var updateRecords []sobject.Updater - - acc1 := &dml{ - sobject: "Account", - fields: map[string]interface{}{ - "Name": "Collections Demo Update", - "Phone": "4805551212", - "Active__c": "No", - }, - id: "0012E00001pXGh2QAG", - } - updateRecords = append(updateRecords, acc1) - acc2 := &dml{ - sobject: "Account", - fields: map[string]interface{}{ - "Name": "Collections Demo Two Update", - "Phone": "6065551212", - "Active__c": "Yes", - }, - id: "0012ExxxAG", - } - updateRecords = append(updateRecords, acc2) - con1 := &dml{ - sobject: "Contact", - fields: map[string]interface{}{ - "LastName": "Last Name Demo Update", - "AssistantPhone": "6065551212", - "Level__c": "Tertiary", - }, - id: "0032ExxxjQAJ", - } - updateRecords = append(updateRecords, con1) - con2 := &dml{ - sobject: "Contact", - fields: map[string]interface{}{ - "LastName": "Last Name Demo Two Update", - "AssistantPhone": "6025551212", - "Level__c": "Tertiary", - }, - id: "0032ExxxkQAJ", - } - updateRecords = append(updateRecords, con2) - - resource := collections.NewResources(session) - values, err := resource.Update(true, updateRecords) - if err != nil { - fmt.Printf("Collection Error %s", err.Error()) - fmt.Println() - return - } - - fmt.Println("Collections Updated") - fmt.Println("-------------------") - for _, value := range values { - fmt.Printf("%+v\n", value) - } +var updateRecords []sobject.Updater + +acc1 := &dml{ + sobject: "Account", + fields: map[string]interface{}{ + "Name": "Collections Demo Update", + "Phone": "4805551212", + "Active__c": "No", + }, + id: "0012E00001pXGh2QAG", +} +updateRecords = append(updateRecords, acc1) +acc2 := &dml{ + sobject: "Account", + fields: map[string]interface{}{ + "Name": "Collections Demo Two Update", + "Phone": "6065551212", + "Active__c": "Yes", + }, + id: "0012ExxxAG", +} +updateRecords = append(updateRecords, acc2) +con1 := &dml{ + sobject: "Contact", + fields: map[string]interface{}{ + "LastName": "Last Name Demo Update", + "AssistantPhone": "6065551212", + "Level__c": "Tertiary", + }, + id: "0032ExxxjQAJ", +} +updateRecords = append(updateRecords, con1) +con2 := &dml{ + sobject: "Contact", + fields: map[string]interface{}{ + "LastName": "Last Name Demo Two Update", + "AssistantPhone": "6025551212", + "Level__c": "Tertiary", + }, + id: "0032ExxxkQAJ", +} +updateRecords = append(updateRecords, con2) + +resource := collections.NewResources(session) +values, err := resource.Update(true, updateRecords) +if err != nil { + fmt.Printf("Collection Error %s", err.Error()) fmt.Println() + return +} + +fmt.Println("Collections Updated") +fmt.Println("-------------------") +for _, value := range values { + fmt.Printf("%+v\n", value) +} +fmt.Println() ``` ### Delete Multiple Records ```go - deleteRecords := []string{ - "0012Exxx2QAG", - "0012Exxx3QAG", - "0032ExxxEjQAJ", - "0032ExxxEkQAJ", - } - - resource := collections.NewResources(session) - values, err := resource.Delete(true, deleteRecords) - if err != nil { - fmt.Printf("Collection Error %s", err.Error()) - fmt.Println() - return - } - - fmt.Println("Collections Deleted") - fmt.Println("-------------------") - for _, value := range values { - fmt.Printf("%+v\n", value) - } - fmt.Println() +deleteRecords := []string{ + "0012Exxx2QAG", + "0012Exxx3QAG", + "0032ExxxEjQAJ", + "0032ExxxEkQAJ", +} + +resource := collections.NewResources(session) +values, err := resource.Delete(true, deleteRecords) +if err != nil { + fmt.Printf("Collection Error %s\n", err.Error()) + return +} + +fmt.Println("Collections Deleted") +fmt.Println("-------------------") +for _, value := range values { + fmt.Printf("%+v\n", value) +} +fmt.Println() ``` ### Retrieve Multiple Records ```go - var queryRecords []sobject.Querier - - acc1 := &query{ - sobject: "Account", - fields: []string{ - "Name", - "Phone", - }, - id: "0012Exxx2QAG", - } - queryRecords = append(queryRecords, acc1) - acc2 := &query{ - sobject: "Account", - fields: []string{ - "Name", - "Active__c", - }, - id: "0012Exxx3QAG", - } - queryRecords = append(queryRecords, acc2) - - resource := collections.NewResources(session) - values, err := resource.Query("Account", queryRecords) - if err != nil { - fmt.Printf("Collection Error %s", err.Error()) - fmt.Println() - return - } - - fmt.Println("Collections Inserted") - fmt.Println("-------------------") - for _, value := range values { - fmt.Printf("%+v\n", *value) - } - fmt.Println() +var queryRecords []sobject.Querier + +acc1 := &query{ + sobject: "Account", + fields: []string{ + "Name", + "Phone", + }, + id: "0012Exxx2QAG", +} +queryRecords = append(queryRecords, acc1) +acc2 := &query{ + sobject: "Account", + fields: []string{ + "Name", + "Active__c", + }, + id: "0012Exxx3QAG", +} +queryRecords = append(queryRecords, acc2) + +resource := collections.NewResources(session) +values, err := resource.Query("Account", queryRecords) +if err != nil { + fmt.Printf("Collection Error %s\n", err.Error()) + return +} + +fmt.Println("Collections Inserted") +fmt.Println("-------------------") +for _, value := range values { + fmt.Printf("%+v\n", *value) +} +fmt.Println() ``` diff --git a/sobject/tree/README.md b/sobject/tree/README.md index 0f5041a..1656345 100644 --- a/sobject/tree/README.md +++ b/sobject/tree/README.md @@ -27,92 +27,87 @@ func (b *treeBuilder) ReferenceID() string { return b.referenceID } - // build some records - accountRef1Builder := &treeBuilder{ - sobject: "Account", - referenceID: "ref1", - fields: map[string]interface{}{ - "name": "SampleAccount11", - "phone": "1234567890", - "website": "www.salesforce.com", - "numberOfEmployees": 100, - "industry": "Banking", - }, - } - accountRef2Builder := &treeBuilder{ - sobject: "Account", - referenceID: "ref4", - fields: map[string]interface{}{ - "name": "SampleAccount112", - "Phone": "1234567890", - "website": "www.salesforce2.com", - "numberOfEmployees": 100, - "industry": "Banking", - }, - } - contactRef3Builder := &treeBuilder{ - sobject: "Contact", - referenceID: "ref2", - fields: map[string]interface{}{ - "lastname": "Smith11", - "title": "President", - "email": "sample@salesforce.com", - }, - } - contactRef4Builder := &treeBuilder{ - sobject: "Contact", - referenceID: "ref3", - fields: map[string]interface{}{ - "lastname": "Evans11", - "title": "Vice President", - "email": "sample@salesforce.com", - }, - } +// build some records +accountRef1Builder := &treeBuilder{ + sobject: "Account", + referenceID: "ref1", + fields: map[string]interface{}{ + "name": "SampleAccount11", + "phone": "1234567890", + "website": "www.salesforce.com", + "numberOfEmployees": 100, + "industry": "Banking", + }, +} +accountRef2Builder := &treeBuilder{ + sobject: "Account", + referenceID: "ref4", + fields: map[string]interface{}{ + "name": "SampleAccount112", + "Phone": "1234567890", + "website": "www.salesforce2.com", + "numberOfEmployees": 100, + "industry": "Banking", + }, +} +contactRef3Builder := &treeBuilder{ + sobject: "Contact", + referenceID: "ref2", + fields: map[string]interface{}{ + "lastname": "Smith11", + "title": "President", + "email": "sample@salesforce.com", + }, +} +contactRef4Builder := &treeBuilder{ + sobject: "Contact", + referenceID: "ref3", + fields: map[string]interface{}{ + "lastname": "Evans11", + "title": "Vice President", + "email": "sample@salesforce.com", + }, +} - account1RecordBuilder, err := tree.NewRecordBuilder(accountRef1Builder) - if err != nil { - fmt.Printf("NewRecordBuilder Error %s", err.Error()) - fmt.Println() - return - } - contact1RecordBuilder, err := tree.NewRecordBuilder(contactRef3Builder) - if err != nil { - fmt.Printf("NewRecordBuilder Error %s", err.Error()) - fmt.Println() - return - } - contact2RecordBuilder, err := tree.NewRecordBuilder(contactRef4Builder) - if err != nil { - fmt.Printf("NewRecordBuilder Error %s", err.Error()) - fmt.Println() - return - } - account1RecordBuilder.SubRecords("contacts", contact1RecordBuilder.Build(), contact2RecordBuilder.Build()) +account1RecordBuilder, err := tree.NewRecordBuilder(accountRef1Builder) +if err != nil { + fmt.Printf("NewRecordBuilder Error %s\n", err.Error()) + return +} +contact1RecordBuilder, err := tree.NewRecordBuilder(contactRef3Builder) +if err != nil { + fmt.Printf("NewRecordBuilder Error %s\n", err.Error()) + return +} +contact2RecordBuilder, err := tree.NewRecordBuilder(contactRef4Builder) +if err != nil { + fmt.Printf("NewRecordBuilder Error %s\n", err.Error()) + return +} +account1RecordBuilder.SubRecords("contacts", contact1RecordBuilder.Build(), contact2RecordBuilder.Build()) - account2RecordBuilder, err := tree.NewRecordBuilder(accountRef2Builder) - if err != nil { - fmt.Printf("NewRecordBuilder Error %s", err.Error()) - fmt.Println() - return - } +account2RecordBuilder, err := tree.NewRecordBuilder(accountRef2Builder) +if err != nil { + fmt.Printf("NewRecordBuilder Error %s\n", err.Error()) + return +} ``` ### Create Accounts with Children ```go - inserter := &treeInserter{ - sobject: "Account", - records: []*tree.Record{ - account1RecordBuilder.Build(), - account2RecordBuilder.Build(), - }, - } - resource := tree.NewResource(session) - value, err := resource.Insert(inserter) - if err != nil { - fmt.Printf("resource.Insert Error %s", err.Error()) - fmt.Println() - return - } - fmt.Printf("%+v\n", *value) +inserter := &treeInserter{ + sobject: "Account", + records: []*tree.Record{ + account1RecordBuilder.Build(), + account2RecordBuilder.Build(), + }, +} +resource := tree.NewResource(session) +value, err := resource.Insert(inserter) +if err != nil { + fmt.Printf("resource.Insert Error %s\n", err.Error()) + return +} +fmt.Printf("%+v\n", *value) ``` diff --git a/soql/README.md b/soql/README.md index 9e9f976..ac0efec 100644 --- a/soql/README.md +++ b/soql/README.md @@ -2,7 +2,7 @@ [back](../README.md) The `soql` package is an implementation of the `Salesforce APIs` centered on `SOQL` operations. These operations include: -* `SOQL` query builder +* `SOQL` query formatter * `SOQL` query * `SOQL` query all @@ -16,8 +16,7 @@ The following examplas cenrter around `SOQL` builder. Although using the builde ```go where, err := soql.WhereEquals("Name", "Golang") if err != nil { - fmt.Printf("SOQL Query Where Statement Error %s", err.Error()) - fmt.Println() + fmt.Printf("SOQL Query Where Statement Error %s\n", err.Error()) return } input := soql.QueryInput{ @@ -30,21 +29,18 @@ The following examplas cenrter around `SOQL` builder. Although using the builde } queryStmt, err := soql.NewQuery(input) if err != nil { - fmt.Printf("SOQL Query Statement Error %s", err.Error()) - fmt.Println() + fmt.Printf("SOQL Query Statement Error %s\n", err.Error()) return } stmt, err := queryStmt.Format() if err != nil { - fmt.Printf("SOQL Query Statement Error %s", err.Error()) - fmt.Println() + fmt.Printf("SOQL Query Statement Error %s\n", err.Error()) return } fmt.Println("SOQL Query Statement") fmt.Println("-------------------") fmt.Println(stmt) - fmt.Println() ``` #### SELECT Name, Id, (SELECT LastName FROM Contacts) FROM Account ```go @@ -56,8 +52,7 @@ The following examplas cenrter around `SOQL` builder. Although using the builde } subQuery, err := soql.NewQuery(subInput) if err != nil { - fmt.Printf("SOQL Sub Query Error %s", err.Error()) - fmt.Println() + fmt.Printf("SOQL Sub Query Error %s\n", err.Error()) return } @@ -73,22 +68,19 @@ The following examplas cenrter around `SOQL` builder. Although using the builde } queryStmt, err := soql.NewQuery(input) if err != nil { - fmt.Printf("SOQL Query Statement Error %s", err.Error()) - fmt.Println() + fmt.Printf("SOQL Query Statement Error %s\n", err.Error()) return } stmt, err := queryStmt.Format() if err != nil { - fmt.Printf("SOQL Query Statement Error %s", err.Error()) - fmt.Println() + fmt.Printf("SOQL Query Statement Error %s\n", err.Error()) return } fmt.Println("SOQL Query Statement") fmt.Println("-------------------") fmt.Println(stmt) - fmt.Println() ``` ### SOQL Query The following example demostrates how to `SOQL` query. It is assumed that a session has need created and a `SOQL` statement has been built. @@ -110,16 +102,14 @@ FROM resource := soql.NewResource(session) result, err := resource.Query(queryStmt, false) if err != nil { - fmt.Printf("SOQL Query Error %s", err.Error()) - fmt.Println() + fmt.Printf("SOQL Query Error %s\n", err.Error()) return } fmt.Println("SOQL Query") fmt.Println("-------------------") fmt.Printf("Done: %t\n", result.Done()) fmt.Printf("Total Size: %d\n", result.TotalSize()) - fmt.Printf("Next Records URL: %t\n", result.MoreRecords()) - fmt.Println() + fmt.Printf("Next Records URL: %t\n\n", result.MoreRecords()) for _, rec := range result.Records() { r := rec.Record()