Last active
December 16, 2015 15:19
-
-
Save j-mcnally/5455048 to your computer and use it in GitHub Desktop.
Salesforce Automation Using Rake
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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