3

I'm having a issue with pulling the data out of what would be a array of object data in my SFDC query. Im using the databasedotcom gem.

Code

def self.data_query

 #@client is defined at a class level

 name = "Bob Jones INC"
 query_str = "SELECT Id, CaseNumber, (SELECT Id, Part_Number__c FROM Serial_Numbers__r) FROM Case WHERE Company ='#{name}'"
 result = @client.query(query_str)

 returned_data = result.first

 #Make Some Variables
 $_ID = returned_data.Id
 $_CASENUMBER = returned_data.CaseNumber

 # Now there is multiple Serial_Numbers__r, how can i capture them (id and Part Number)
 # I was thinking something like this, but it doesnt work. returns error about serial_numbers__r

 $_ARRAY = []     

 returned_data.Serial_Numbers__r do { |x|
     $_ARRAY << { serial_id => x.Id, serial_partnum => x.Part_Number__c}
 }
 end

 response = "Data is equals #{$_ID}, #{$_CASENUMBER} and Array #{$_ARRAY.each}"

end #data_query

....

puts "begin"
data_query

Currently this causing a NoMethod error on Serial_Numbers__r on the returned_data object

2
  • Yo dawg, I heard you liked queries, so I put a query in your query so you can query while you query. (Couldn't resist.) Apr 16 '14 at 21:19
  • hahaha @DavidSchach Apr 16 '14 at 21:22
1

The lack of support for relationships appears to be an open issue Nested Associations/Relationships that is Array-based. A couple of forks are mentioned that perhaps you could use.

(No commits to the project in the last year - not encouraging.)

From Accessing Salesforce Data from Ruby:

One of the most important gem limitations is a lack of support for relationships — no belongs_to, has_many, and so forth. Handling relationships yourself isn't as much of a burden as you might expect because relationships between Salesforce objects are typically much simpler than you're used to in traditional RDBMS schemas. The Salesforce query language, SOQL, is designed to solve a well-defined and restricted set of problems, and to keep things running smoothly in Salesforce's shared cloud.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.