Skip to content

gfteix/sf_go_client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SF GO Client

A simple Salesforce API client.

Initiating the client

For now, only the password auth is supported.

Make sure the following environment variables are defined

USERNAME=
PASSWORD=
CLIENT_ID=
CLIENT_SECRET=
ORG_URL=
API_VERSION=

Call the NewSalesforceClient to retrieve a new client

    client := NewSalesforceClient()

Rest API

Creating a record

	newAccount := make(map[string]interface{})
	newAccount["Name"] = "New Account"

	id, err := Create(CreateProps{
		client:     client,
		objectType: "Account",
		body:       newAccount,
	})

	if err != nil {
		log.Printf("Error while creating new account %v", err)
	}

Updating a record

	account := make(map[string]interface{})
	account["Name"] = "Updated Value"

	err := Update(UpdateProps{
		client:     client,
		objectType: "Account",
		recordId: 	"recordId",
		body:       account,
	})

	if err != nil {
		log.Printf("Error while updating account %v", err)
	}

Deleting a record

	err := Delete(DeleteProps{
		client: client, 
		objectType: "Account", 
		recordId: "Salesforce RecordId",
	})

	if err != nil {
		log.Printf("Error while deleting account %v", err)
	}

Query

	query := fmt.Sprintf("SELECT Id, Name, Parent.Name, CreatedDate FROM Account WHERE Id = '%v'", id)
	result, err := Query(client, query)

	if err != nil {
		log.Panic("Failed to query Salesforce")
	}

	// Priting the result
	
	for index, record := range result {
		log.Printf("Index %v", index)
	
		for key, value := range record {
			log.Printf("%s: %v", key, value)
			log.Printf("Type: %v", reflect.TypeOf(value))
		}
	}

Metadata API (TODO)

Composite API (TODO)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages