From 1f0c9221bfe9d87877efd3d102fd7544909491c8 Mon Sep 17 00:00:00 2001 From: TivonB-AI2 <124182151+TivonB-AI2@users.noreply.github.com> Date: Fri, 22 Nov 2024 08:19:31 -0500 Subject: [PATCH] chore(CE): change destination_insert to create in salesforce crm (#609) --- integrations/Gemfile.lock | 2 +- .../destination/salesforce_crm/client.rb | 30 +++++-------------- .../lib/multiwoven/integrations/rollout.rb | 2 +- .../destination/salesforce_crm/client_spec.rb | 4 +-- 4 files changed, 11 insertions(+), 27 deletions(-) diff --git a/integrations/Gemfile.lock b/integrations/Gemfile.lock index 1736fb40..6793599f 100644 --- a/integrations/Gemfile.lock +++ b/integrations/Gemfile.lock @@ -7,7 +7,7 @@ GIT PATH remote: . specs: - multiwoven-integrations (0.15.5) + multiwoven-integrations (0.15.6) MailchimpMarketing activesupport async-websocket diff --git a/integrations/lib/multiwoven/integrations/destination/salesforce_crm/client.rb b/integrations/lib/multiwoven/integrations/destination/salesforce_crm/client.rb index 6bdf0914..2c74da81 100644 --- a/integrations/lib/multiwoven/integrations/destination/salesforce_crm/client.rb +++ b/integrations/lib/multiwoven/integrations/destination/salesforce_crm/client.rb @@ -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, { @@ -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 diff --git a/integrations/lib/multiwoven/integrations/rollout.rb b/integrations/lib/multiwoven/integrations/rollout.rb index b9142319..2d6f2de9 100644 --- a/integrations/lib/multiwoven/integrations/rollout.rb +++ b/integrations/lib/multiwoven/integrations/rollout.rb @@ -2,7 +2,7 @@ module Multiwoven module Integrations - VERSION = "0.15.5" + VERSION = "0.15.6" ENABLED_SOURCES = %w[ Snowflake diff --git a/integrations/spec/multiwoven/integrations/destination/salesforce_crm/client_spec.rb b/integrations/spec/multiwoven/integrations/destination/salesforce_crm/client_spec.rb index 61d136f2..071cefc1 100644 --- a/integrations/spec/multiwoven/integrations/destination/salesforce_crm/client_spec.rb +++ b/integrations/spec/multiwoven/integrations/destination/salesforce_crm/client_spec.rb @@ -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: {})