Skip to content

Commit

Permalink
chore(CE): change destination_insert to create in salesforce crm (#490)
Browse files Browse the repository at this point in the history
Co-authored-by: TivonB-AI2
  • Loading branch information
github-actions[bot] authored Nov 25, 2024
1 parent 5481b08 commit 45615a7
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 27 deletions.
2 changes: 1 addition & 1 deletion integrations/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ GIT
PATH
remote: .
specs:
multiwoven-integrations (0.15.5)
multiwoven-integrations (0.15.6)
MailchimpMarketing
activesupport
async-websocket
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,10 @@ def process_records(records, stream)
properties = stream.json_schema[:properties]
records.each do |record_object|
record = extract_data(record_object, properties)
request, response = *process_record(stream, record)
args = [stream.name, "Id", record]
response = send_data_to_salesforce(args)
write_success += 1
log_message_array << log_request_response("info", request, response)
log_message_array << log_request_response("info", args, response)
rescue StandardError => e
# TODO: add sync_id and sync_run_id to the logs
handle_exception(e, {
Expand All @@ -77,31 +78,14 @@ def process_records(records, stream)
sync_run_id: @sync_config.sync_run_id
})
write_failure += 1
log_message_array << log_request_response("error", request, e.message)
log_message_array << log_request_response("error", args, e.message)
end
tracking_message(write_success, write_failure, log_message_array)
end

def process_record(stream, record)
send_data_to_salesforce(stream.name, record)
end

def send_data_to_salesforce(stream_name, record = {})
method_name = "#{@action}!"
args = build_args(@action, stream_name, record)
response = @client.send(method_name, *args)
[args, response]
end

def build_args(action, stream_name, record)
case action
when :upsert
[stream_name, record[:external_key], record]
when :destroy
[stream_name, record[:id]]
else
[stream_name, record]
end
def send_data_to_salesforce(args)
method_name = "upsert!"
@client.send(method_name, *args)
end

def authenticate_client
Expand Down
2 changes: 1 addition & 1 deletion integrations/lib/multiwoven/integrations/rollout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Multiwoven
module Integrations
VERSION = "0.15.5"
VERSION = "0.15.6"

ENABLED_SOURCES = %w[
Snowflake
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ def build_record(id, name)
end

def stub_create_request(id, name, response_code)
stub_request(:post, "https://your-instance-url.salesforce.com/services/data/v59.0/sobjects/Account")
stub_request(:patch, "https://your-instance-url.salesforce.com/services/data/v59.0/sobjects/Account/Id/#{id}")
.with(
body: hash_including("Id" => id, "Name" => name),
body: hash_including({ "Name": name }),
headers: { "Accept" => "*/*", "Authorization" => "OAuth",
"Content-Type" => "application/json" }
).to_return(status: response_code, body: "", headers: {})
Expand Down

0 comments on commit 45615a7

Please sign in to comment.