nimajalali / go-force Goto Github PK
View Code? Open in Web Editor NEWGo (golang) library for calling Salesforce.com (force.com) web api's
License: MIT License
Go (golang) library for calling Salesforce.com (force.com) web api's
License: MIT License
Using the describe API we should be able to auto generate the go source code for sobject models.
Hi, I believe that v36 of the Salesforce API is returning actual JSON literal true/false values instead of strings for the SObjectField DefaultValue field, which is causing the unmarshalling to fail, which produces this error message:
Unable to unmarshal response to object: force: cannot unmarshal bool into Go value of type string
I couldn't come up with a quick fix, as you'd need to dynamically set the type of DefaultValue based on the value of "Type". One possibility would be to use a generic interface{} as the type of DefaultValue and then users would have to use reflection + a type assertion to massage it back into the correct type.
Hi,
Can you please help to solve this
I am trying to call below function on Google AppEngine development server and getting the error.
But without appengine getting the record details from salesforce.
func init() {
// Init the force
forceApi, err := force.Create(
"v39.0",
"****************************************",
"*******",
"****@*****.com",
"******",
"*******",
"production",
)
if err != nil {
log.Fatal(err)
}
// Get somCustomSObject by ID
someCustomSObject := &SomeCustomSObject{}
err = forceApi.GetSObject("a0K0I00000DlwBQ", nil, someCustomSObject)
if err != nil {
fmt.Println(err)
}
fmt.Printf("%#v", someCustomSObject)
I am getting below error
the runtime process for the instance running on port 57472 has unexpectedly quit
2018/08/21 15:16:24 Error sending authentication request: Post https://login.salesforce.com/services/oauth2/token: http.DefaultTransport and http.DefaultClient are not available in App Engine. See https://cloud.google.com/appengine/docs/go/urlfetch/
Hi we are active users of go-force over at pflege-de, so we chose to spin off our own fork, seeing a lack of activity on the original repository.
We have implemented a few fixes and improvements, but we have not yet gotten around reviewing existing issues/PRs in the original issues that do not immediately affect us.
If you want to give it a try, or join in improving the client come over here:
Due to various reasons, the http.DefaultClient used by default might not be appropriate to use. It would be nice to be able to specify what client to use for requests.
Could you add to SObjectField type (github.com/nimajalali/go-force/force/api.go) this field:
CalculatedFormula string
json:"calculatedFormula"
Thank you.
SF supports custom objects with multiple fields set to External ID. Current implementation only allows for one.
The Salesforce API allows gzip compression on either request entities or response entities (or both). It's not to hard to support this by using the necessary Content-Encoding
and Accept-Encoding
headers and then passing the json marshalling through compress/gzip
functions.
The only method affected is ForceApi.request
, I think.
When using BuildQuery
and Query
to run a query the following query returns the expected results:
SELECT Id FROM PermissionSetAssignment
But when the query uses the dot notation for the related object there are no results:
SELECT PermissionSet.Id, PermissionSet.Name FROM PermissionSetAssignment
The structs for reference:
type PermissionSetAssignment struct {
// ID string `force:"Id"`
ID string `force:"PermissionSet.Id"`
Name string `force:"PermissionSet.Name"`
}
type PermissionSetAssignmentResponse struct {
sobjects.BaseQuery
Records []*PermissionSetAssignment `force:"records"`
}
What am i missing?
This is with Ubuntu 16.04 with the "official" go 1.8.1 distribution in /usr/local/go
I am trying to run the example code at https://github.com/nimajalali/go-force/blob/master/README.md
$ go run test-force.go
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x48 pc=0x60ee96]
goroutine 1 [running]:
github.com/nimajalali/go-force/force.(*ForceApi).GetSObject(0xc420058240, 0x69a5e8, 0xe, 0x0, 0x0, 0x0, 0x7a4c40, 0xc4200188f0, 0x699eb7, 0xc)
/home/ubuntu/go/src/github.com/nimajalali/go-force/force/sobjects.go:75 +0x86
main.main()
/home/ubuntu/go/src/test-force/test-force.go:45 +0x1a5
exit status 2
Attempting to get a bit more info with gdb:
go build -gcflags "-N -l"
...
gdb -d $(go env GOROOT) ./test-force
...
run
...
[Switching to Thread 0x7ffff67ee700 (LWP 5972)]
0x000000000060ee96 in github.com/nimajalali/go-force/force.(*ForceApi).GetSObject (
forceApi=0xc420058240, id=..., fields=..., out=..., err=...)
at /home/ubuntu/go/src/github.com/nimajalali/go-force/force/sobjects.go:75
75 uri := strings.Replace(forceApi.apiSObjects[out.ApiName()].URLs[rowTemplateKey], idKey, id, 1)
(gdb) info args
forceApi = 0xc420058240
id = 0x69a5e8 "Your-Object-ID"
fields = {array = 0x0, len = 0, cap = 0}
out = {tab = 0x7a4c40 <com/nimajalali/go-force/force.SObject>, data = 0xc4200188f0}
err = {tab = 0x699eb7, data = 0xc}
(gdb) info locals
value·3.len = 842350821952
uri.len = 0
v·1 = 0xc4200fdd50
value·3.ptr = 0x410b18 <runtime.newobject+56> "H\213D$\030H\211D$8H\213l$ H\203\304(\303\350\217\"\004"
uri.ptr = 0xb0 <error: Cannot access memory at address 0xb0>
(gdb)
I am quite happy of course that there will be no object with ID "Your-Object-ID"; and maybe the credentials I supplied are invalid (although they seem OK, e.g. if I alter the password I get an authentication error)
But either way, I don't think go-force should panic in this situation.
I'm working on this now and hopefully will be submitting a PR soon, but I wanted an issue here for reference
Expose ForceApi as an interface so we can create a mock.
Wondering what the best practice is for sending different queries to the same SObject.
ex:
Would I want to create a new SomeNameSObjectQueryResponse for each of these queries or do I need to get the response and drop the fields from the response before working with it?
Still new to Go so any help here would be amazing! Thanks
When adding or editing custom objects in Salesforce the api resources become invalid and need to be refreshed.
Today you have to restart the process to initiate a refresh.
The following resources should be refreshed when this method is called:
apiResources
apiSObjects
apiSObjectDescriptions
apiMaxBatchSize
as an example;
var results *Account = new(Account)
err = fa.Query("SELECT Id, Name, BillingCity FROM Account LIMIT 10", &results)
Will retrieve one result.... How do I retrieve more than one row?
Today if you attempt to interact with an SObject that doesn't exist in SalesForce the force package will panic.
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x48 pc=0x49f87]
goroutine 16 [running]:
runtime.panic(0x2a48a0, 0x4638e4)
/usr/local/Cellar/go/1.3.3/libexec/src/pkg/runtime/panic.c:279 +0xf5
github.com/nimajalali/go-force/force.(*ForceApi).GetSObject(0xc208004180, 0x2eba50, 0xe, 0x51def0, 0xc208210000, 0x0, 0x0)
/Users/njalali/Documents/go/src/github.com/nimajalali/go-force/force/sobjects.go:68 +0x137
Instead of a panic we should return a meaningful error. To do this we should verify the object metadata exists in the forceApi.apiSObjects map before trying to access it.
e.g.
data, ok := forceApi.apiSObjects["SOME_OBJECT_NAME"]
if !ok {
return fmt.Errorf("Unable to find metadata for object: %s", "SOME_OBJECT_NAME")
}
Hey!
So I saw this: #37 and I was like "nice, it should be working". Sadly, it isn't (and I really need to use the refresh token). The PR included in the issue I've mentioned does not even make sense, it basically just declare a few variables and interfaces and called it a day.
There are a lot of problems with your current request
method that won't allow an easy implementation of refreshToken (wrong content-type, wrong way of sending the body to the request, etc), I've just forked your project and got some progress but unfortunately I'm stuck in unmarshaling the response body. Perhaps it would be easier to write an entire different request function only for the refresh flow meanwhile, I don't know.
I'll not provide a PR for this (as of now) because I'm still figuring out your code, the progress I made so far, while workable, is ugly hahaha So consider this issue a feature request for now. I'll provide updates if I get some progress but I believe you can easily fix the refresh flow on your end in half hour.
Nice code by the way :)
EDIT: here's a PR with a (ugly but working) fix: #41
Currently calling ForceApi.UpsertSObjectByExternalId
would return an object unmarshal error when salesforce endpoint returns a 204. The code causing this behavior is in ForceApi.request
which attempts to unmarshal an empty response byte slice.
Hello nimajalali,
Recently I discovered a tool called FileStash: https://www.filestash.app
For my use case there are 2 connectors missing and one of them is a Salesforce files connector. I discovered your package and I think it could be a good fit to be used for this connector. The reason I guess is that Filestash package also includes an aws s3 connector making use of the aws-sdk-go
Me myself I have good knowledge of salesforce coding but have no knowledge of Go(lang).
Would you be interested to get involved?
Please let me know.
Kind regards,
Mario
Is there any way to easily read back a Salesforce Date/Time object into a golang time.Time object?
I can write a Golang time.Time object into the Salesforce Date/Time object, but I cannot go the other way. I get this error: "Unable to unmarshal response to object: parsing time ""1965-04-06T00:00:00.000+0000"" as ""2006-01-02T15:04:05Z07:00"": cannot parse "+0000"" as "Z07:00"1"
How can I achieve this?
Thanks!
Hi Nima, Thanks for the excellent work with this library!
I would like to use the library in a closed source project for a client, (and possibly assist with any bugs etc which might come up while I do).
Are you able to add an open source licence (E.G. MIT) to the github repo?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.