undees/rforce — Issue #15: Multi-Record DML Operations with Same sObject cause undefined method `to_sym'
Author: rbrainard
Created: 2012-01-31 07:52:46+00:00
State: open

As a follow up to Issue 14, in muti-record DML operations when the same sObject is used for more than one slot in the array a `Uncaught exception: undefined method to_sym` error occurs. See below for full stack trace.

For example, given the following data:

account1 = [
:type, 'Account',
:name, 'ALPHA',
]

account2 = [
:type, 'Account',
:name, 'BETA',
]

creating the records like this _works_ because `account1` and `account2` are used separely:

puts sfdc.create([:sObjects, account1, :sObjects, account2])

with this output including a debugging line in `RForce::expand()` to see the args being passed recursively:

RForce::expand() args: {:create=>[:sObjects, [:type, "Account", :name, "ALPHA"], :sObjects, [:type, "Account", :name, "BETA"]]}
RForce::expand() args: [:sObjects, [:type, "Account", :name, "ALPHA"], :sObjects, [:type, "Account", :name, "BETA"]]
RForce::expand() args: [:type, "Account", :name, "ALPHA"]
RForce::expand() args: [:type, "Account", :name, "BETA"]

and this XML is created

AccountALPHAAccountBETA

and this response is returned:

{:createResponse=>{:result=>[{:id=>"0016000000gHjVrAAK", :success=>"true"}, {:id=>"0016000000gHjVsAAK", :success=>"true"}]}}

----------------

Compare that with using the same object for both slots, which _does not work_ and blows up in the XML parsing:

puts sfdc.create([:sObjects, account1, :sObjects, account1])

Output:

RForce::expand() args: {:create=>[:sObjects, [:type, "Account", :name, "ALPHA"], :sObjects, [:type, "Account", :name, "ALPHA"]]}
RForce::expand() args: [:sObjects, [:type, "Account", :name, "ALPHA"], :sObjects, [:type, "Account", :name, "ALPHA"]]
RForce::expand() args: [:type, "Account", :name, "ALPHA"]
RForce::expand() args: [[:type, "Account"], [:name, "ALPHA"]]
Uncaught exception: undefined method `to_sym' for [:type, "Account"]:Array
/Users/brainard/.rvm/gems/ruby-1.9.2-p290/gems/builder-3.0.0/lib/builder/xmlbase.rb:34:in `tag!'
/Users/brainard/.rvm/gems/ruby-1.9.2-p290/gems/rforce-0.8.1/lib/rforce.rb:80:in `block in expand'
/Users/brainard/.rvm/gems/ruby-1.9.2-p290/gems/rforce-0.8.1/lib/rforce.rb:60:in `each'
/Users/brainard/.rvm/gems/ruby-1.9.2-p290/gems/rforce-0.8.1/lib/rforce.rb:60:in `expand'
/Users/brainard/.rvm/gems/ruby-1.9.2-p290/gems/rforce-0.8.1/lib/rforce.rb:80:in `block (2 levels) in expand'
/Users/brainard/.rvm/gems/ruby-1.9.2-p290/gems/builder-3.0.0/lib/builder/xmlbase.rb:155:in `call'
/Users/brainard/.rvm/gems/ruby-1.9.2-p290/gems/builder-3.0.0/lib/builder/xmlbase.rb:155:in `_nested_structures'
/Users/brainard/.rvm/gems/ruby-1.9.2-p290/gems/builder-3.0.0/lib/builder/xmlbase.rb:63:in `method_missing'
/Users/brainard/.rvm/gems/ruby-1.9.2-p290/gems/builder-3.0.0/lib/builder/xmlbase.rb:34:in `tag!'
/Users/brainard/.rvm/gems/ruby-1.9.2-p290/gems/rforce-0.8.1/lib/rforce.rb:80:in `block in expand'
/Users/brainard/.rvm/gems/ruby-1.9.2-p290/gems/rforce-0.8.1/lib/rforce.rb:60:in `each'
/Users/brainard/.rvm/gems/ruby-1.9.2-p290/gems/rforce-0.8.1/lib/rforce.rb:60:in `expand'
/Users/brainard/.rvm/gems/ruby-1.9.2-p290/gems/rforce-0.8.1/lib/rforce.rb:80:in `block (2 levels) in expand'
/Users/brainard/.rvm/gems/ruby-1.9.2-p290/gems/builder-3.0.0/lib/builder/xmlbase.rb:155:in `call'
/Users/brainard/.rvm/gems/ruby-1.9.2-p290/gems/builder-3.0.0/lib/builder/xmlbase.rb:155:in `_nested_structures'
/Users/brainard/.rvm/gems/ruby-1.9.2-p290/gems/builder-3.0.0/lib/builder/xmlbase.rb:63:in `method_missing'
/Users/brainard/.rvm/gems/ruby-1.9.2-p290/gems/builder-3.0.0/lib/builder/xmlbase.rb:34:in `tag!'
/Users/brainard/.rvm/gems/ruby-1.9.2-p290/gems/rforce-0.8.1/lib/rforce.rb:80:in `block in expand'
/Users/brainard/.rvm/gems/ruby-1.9.2-p290/gems/rforce-0.8.1/lib/rforce.rb:60:in `each'
/Users/brainard/.rvm/gems/ruby-1.9.2-p290/gems/rforce-0.8.1/lib/rforce.rb:60:in `expand'
/Users/brainard/.rvm/gems/ruby-1.9.2-p290/gems/rforce-0.8.1/lib/rforce/binding.rb:161:in `call_remote'
/Users/brainard/.rvm/gems/ruby-1.9.2-p290/gems/rforce-0.8.1/lib/rforce/binding.rb:270:in `method_missing'
/Users/brainard/Development/ruby-play/sfdc.rb:19:in `'