Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Domain Patch #66

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ You can use as many records possible in the Array. Governor limits are taken car

OR

Username Password Combo:

require 'salesforce_bulk_api'
client = Restforce.new(
username: SFDC_APP_CONFIG['SFDC_USERNAME'],
Expand All @@ -49,6 +51,20 @@ OR
client.authenticate!
salesforce = SalesforceBulkApi::Api.new(client)

OAuth2 Combo:

require 'salesforce_bulk_api'
client = Restforce.new(
security_token: SFDC_APP_CONFIG['SFDC_SECURITY_TOKEN'],
refresh_token: SFDC_APP_CONFIG['SFDC_REFRESH_TOKEN'],
client_id: SFDC_APP_CONFIG['SFDC_CLIENT_ID'],
client_secret: SFDC_APP_CONFIG['SFDC_CLIENT_SECRET'].to_i,
host: SFDC_APP_CONFIG['SFDC_HOST']
)
client.authenticate!
salesforce = SalesforceBulkApi::Api.new(client)

Note: The authenticate! method of Restforce requires the presence of username, password, client id and client secret in case of username-password mode of authentication and refresh token, client id and client secret if you are going the OAuth way for authenticating with Restforce. If those options are not set, you will receive 'No authentication middleware present' error.

### Sample operations:

Expand Down
9 changes: 8 additions & 1 deletion lib/salesforce_bulk_api/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,15 @@ def https(host)
end

def parse_instance()
@instance = @server_url.match(/https:\/\/[a-z]{2}[0-9]{1,2}/).to_s.gsub("https://","")

#Edited by AD to include scenarios where the domain name is something like 'ab12cdef' and the salesforce instance url is 'ab12cdef.my.salesforce.com'.
#In that case, as per the original case, the @instance variable will evaluate to 'ab12.salesforce.com' instead of 'ab12cdef.my.salesforce.com'.
#That would lead to this error --> "Failed to open TCP connection to ab12.salesforce.com:443 (getaddrinfo: Name or service not known)".
#In the following lines of code, we are checking to see if there is a '.' following the earlier regex to ensure that its not some fancy custom domain name.

@instance = @server_url.match(/https:\/\/[a-z]{2}[0-9]{1,2}\./).to_s.gsub("https://","").split(".")[0]
@instance = @server_url.split(".salesforce.com")[0].split("://")[1] if @instance.nil? || @instance.empty?

return @instance
end

Expand Down