function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
KunjanKunjan 

How to use sub query to fetch records from salesforce using ruby?

Hi,

 

Can anyone tell me how to use sub query in ruby to fetch records from salesforce org ?

 

Thanks in advance,

cloudcodercloudcoder

You need to use Salesforce:SfBase.query_by_sql('your soql string')   (bad method name I know!)

 

Few things to note when using this method. Unlike using the standard Active-Record type Salesforce::StandardObject.find(..) methods, you need to use the Force.com object and field names including the __c if it is a custom object/field.

 

If you want a more complex example demonstrating subquerues, check out chatter_feed.rb in the asf-soap-adapter gem.

KunjanKunjan

I already tried with Salesforce::SfBase.query_by_sql, but it throws below error.

 

undefined method `result' for nil:NilClass

 

If I am missing to implement result method in my controller, then please let me know how?

Or let me know just what to do to get rid of this error.

 

cloudcodercloudcoder

Your problem is in how you are handling the response. I suspect you are iterating through a collection, and missing the 'records' keyword Try something like:

 

myOuterObject.myInnerCollection.records do .....

 

A good way to check is to output your collection with the puts command and you will be able to see the structure of the response better. 

 

HTH