In order to bulkify the API operations, you need to wrap the request in another array with some consistent symbol such as the key for each value.
For example, in order to create two opportunities, do the following:
opportunity1 = [
:type, 'Opportunity',
:amount, '10.00',
:name, 'OPP1',
:closeDate, '2008-07-04',
:stageName, 'Closed Won'
]
opportunity2 = [
:type, 'Opportunity',
:amount, '10.00',
:name, 'OPP2',
:closeDate, '2008-07-04',
:stageName, 'Closed Won'
]
puts binding.create([:sObjects, opportunity1, :sObjects, opportunity2])
The following XML is created behind the scenes and is sen to SDFC:
<create xmlns="urn:partner.soap.sforce.com">
<sObjects>
<type>Opportunity</type>
<amount>10.00</amount>
<name>OPP1</name>
<closeDate>2008-07-04</closeDate>
<stageName>Closed Won</stageName>
</sObjects>
<sObjects>
<type>Opportunity</type>
<amount>10.00</amount>
<name>OPP2</name>
<closeDate>2008-07-04</closeDate>
<stageName>Closed Won</stageName>
</sObjects>
</create>
The response for two opportunities created at once is:
{:createResponse=>{:result=>[{:id=>"0066000000KNMrOAAX", :success=>"true"}, {:id=>"0066000000KNMrPAAX", :success=>"true"}]}}
Become a certified Salesforce professional by going for Intellipaat’s Salesforce Certification!