Skip to content

Instantly share code, notes, and snippets.

@j-mcnally
Last active December 16, 2015 15:19
Show Gist options
  • Select an option

  • Save j-mcnally/5455048 to your computer and use it in GitHub Desktop.

Select an option

Save j-mcnally/5455048 to your computer and use it in GitHub Desktop.
Salesforce Automation Using Rake
#salesforce automation via rake using the DataBaseDotCom gem
namespace :salesforce do
desc "add salesforce ids to products"
task :match_products => :environment do
client = Databasedotcom::Client.new :host => SFDC_DOMAIN, :client_id => SFDC_APP_ID, :client_secret => SFDC_APP_SECRET
client.authenticate :username => SFDC_EMAIL, :password => SFDC_PASSWORD_AND_TOKEN
#materialize Sobject
client.sobject_module = SFDC::Objects
cl = client.materialize("Product2")
clpb = client.materialize("PricebookEntry")
Productmodel.all.each do |p|
codes = p.product_code.split(" ")
pr = nil
codes.each do |c|
pr = cl.find_by_productcode(c)
break if pr.present?
end
if pr.present?
pbe = clpb.find_by_Product2Id(pr.Id)
puts pbe.Id
p.sfdc = pbe.Id
p.save
else
puts "Unable to match #{p.product_code}"
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment