g8rswimmer / go-sfdc Goto Github PK
View Code? Open in Web Editor NEWgo-sfdc is a library used to interface to Salesforce APIs using golang
License: MIT License
go-sfdc is a library used to interface to Salesforce APIs using golang
License: MIT License
This is more of a question hoping to prompt discussion.
Using soql.Builder
as an example, could most of its fields simply be exported? I say this because many of the builder's methods are simply doing a direct assignment.
For the fields that require additional logic/validation/etc. then those respective methods can remain in place for assignment.
At that point, maybe it isn't a "builder" per se, but maybe rather a soql.Opts
struct.
I wonder if that would simplify your lib even further (and it is already very readable and well documented). It's that much fewer API components that the consumer would need to concern themselves with.
It seems the package is designed to obtain its own session. I'm working from the idea that a calling org will provide a session for me to use and I do not obtain my own.
To make this work I needed to override part of the Session package but still provide a set of fake Credentials just to get a session created.
I wanted to put this up for discussion before I tried to mangle the package via PR.
I changed session.sessionPasswordResponse
to be exported then created an alternate session.Open function that would accept it in and create a Session without trying to login. Staying compatible with the current Session interface so I could pass my session to your systems.
I don't think this solution is very clean because it still requires a sfdc.Configuration object with all the OAuth properties.
// SessionPasswordResponse is the relevant connection details for Salesforce
type SessionPasswordResponse struct {
AccessToken string `json:"access_token"`
InstanceURL string `json:"instance_url"`
TokenType string
}
// Open is used to authenticate with Salesforce and open a session. The user will need to
// supply the proper credentials and a HTTP client.
func Open(config sfdc.Configuration, resp *SessionPasswordResponse) (*Session, error) {
if config.Credentials == nil {
return nil, errors.New("session: configuration crendentials can not be nil")
}
if config.Client == nil {
return nil, errors.New("session: configuration client can not be nil")
}
if config.Version <= 0 {
return nil, errors.New("session: configuration version can not be less than zero")
}
session := &Session{
response: resp,
config: config,
}
return session, nil
}
I'm getting the issue below with upserting a External ID. Thoughts Thanks!
This
NOT_FOUND: Provided external ID field does not exist or is not accessible:
Code below
dml := &dml{
sobject: "Facebook_7FF__c",
fields: map[string]interface{}{
"Ad_Spent_Cents__c": "$10000",
"Clicks__c": "200",
"Entered_Date_Time__c": "12/4/2019, 5:10:20 PM",
"LMS_ID__c": "2324",
"LMS_Record_ID__c": "e4f5591f-ca42-4eb5-bd4b-3d6a1d1b2602",
"Leads__c": "5",
"Period_End_Date__c": "11/27/2019",
"Period_Start_Date__c": "11/27/2019",
"Sales_Cents__c": "$2000",
"Scheduled_ss__c": "2",
"Person_Account__c": "a293i0000009ErBAAU",
"clients__c": "1",
"ss__c": "1",
},
}
dml.id = "a293i0000009ErBAAU"
dml.externalField = "75bc21b7-201c-4a90-b716-506785a0c2a0"
I noticed that there are some incorrect or out of context error messages when I was looking into #33 .
To reproduce, I called resource.Query()
, revoked an access token, and got an error returned.
The error for the call to Query()
was insert response err: INVALID_SESSION_ID: Session expired or invalid...
(not in regards to a insert
)
In fact, this might be an issue in multiple places in the codebase after doing a quick search.
Add a license to the project before opening it up to "the world."
Add some methods that will use reflection and tags to map salesforce fields to a struct and struct to a map of fields
Any planning to have Query function on Bulk 2.0 ? (services/data/v47.0/jobs/query)
Will be GA next month and is already available by sandbox.
Hey g8rswimmer, thank for this repository. I am new to Go and I confused with the "map[string]interface{}" function, how does the system know why type of field it is? Also, do you know of examples of code that shows your code implemented. I appreciate it!
DD
resolves #22
Hello,
Is there any estimation that you will implement the API requests using NewRequestWithContext instead of NewRequest so we will be able to pass our context?
Thanks in advanced.
What is the desired behavior when an OAuth token is expired/invalid?
For example, I created a session
, initialized a Resource
and then called resource.Query()
in a loop on a 5 second delay just to simulate some typical usage by an automated client.
I logged into my Org and removed the client's session.
SFDC returns INVALID_SESSION_ID: Session expired or invalid
, obviously. Thus, an error is returned (I assumed via the call to queryResponse()
.
Running a SOQL query like "SELECT Id, AccountId, Account.Name FROM Contact" causes an error because the processor sees a nested object and thinks it is a nested list of results caused by querying from a top-down lookup where this is a bottom-up lookup and errors with SOQL Query Error query response: done is not present
Remembering that these can actually be nested up to five levels.
I'm not familiar enough with the package yet to know if I'm doing something wrong. Problem appears to be generally located in the assumptions held that if it isn't an attributes
key then it must be a nested query.
soql\record.go--newQueryRecord:19
if k != sfdc.RecordAttributes {
Returned data is in the form
{
"totalSize": 1,
"done": true,
"records": [
{
"attributes": {
"type": "Contact",
"url": "/services/data/v45.0/sobjects/Contact/003XXXXXXXXXXXXXXX"
},
"Id": "003XXXXXXXXXXXXXXX",
"AccountId": "001XXXXXXXXXXXXXXX",
"Account": {
"attributes": {
"type": "Account",
"url": "/services/data/v45.0/sobjects/Account/001XXXXXXXXXXXXXXX"
},
"Name": "Test Account"
}
}
]
}
I'll try and figure it out and get a PR submitted.
I was using this for a project and noticed that Salesforce expects a map[string]string
instead of map[string][]string
for the httpHeaders
field in composite subrequests.
When I use
"httpHeaders": {
"Some-Header": ["defg"]
}
I get the error
[
{
"message": "Invalid type provided for value in 'httpHeaders'",
"errorCode": "JSON_PARSER_ERROR"
}
]
and the request works when I use
"httpHeaders": {
"Some-Header": "defg"
}
cannot use pwdCreds (type *"go-sfdc/credentials".Credentials) as type *"github.com/g8rswimmer/go-sfdc/credentials".Credentials in field value
Prefer doing this before opening up to the community.
Targets for a lib
would likely include
test
docs
deps
(if applicable; use Go Modules)Happy to provide some samples if desired.
Look into adding functionality to the API to support the caller's own type being deserialized.
This would be similar to a GORM query. For example:
var c customStruct
if err := resource.NeatQuery(&c); err != nil {
log.Println(err)
}
fmt.Println(c.Name)
Since the SFDC services return JSON, I think this would simply end up wrapping json.Unmarshal
.
See what it would take to extend this client sdk and keep it backwards compatible.
Use this issue for conversation, suggestions, etc.
Hi g8rswimmer,
first off - love your repo. i'm experiementing trying to use the "Next" function of the query result and can't get past a nil pointer dereference.
Do you have any sample code that i could quickly look out that demonstrates how to paginate through a large query REsult?
Thanks!
Support the Salesforce Bulk APIs (1.0 and 2.0)
https://developer.salesforce.com/docs/atlas.en-us.api_asynch.meta/api_asynch/asynch_api_intro.htm
feature request: Bulk 1.0 API
Support SFDC Streaming API
https://developer.salesforce.com/docs/atlas.en-us.api_streaming.meta/api_streaming/intro_stream.htm
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.