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
Attribution to: Jaison Brooks
Possible Suggestion/Solution #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.
Attribution to: Keith C
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/32938