I am working on a javascript hybrid App. I have a soup declared with along with the model collection:

// The Collection Model
app.models.SerieCollection = Force.SObjectCollection.extend({
    model: app.models.Serie,
    fieldlist : ["Id", "some_field__c"],  
    cache: function() { return app.seriesCache;},

And the soup

app.seriesCache = new Force.StoreCache("series", [{path:"Id", type:"string"}]);

Later on in the app I want use SmartQuery to get all the entries which have some_other_field__c = 'some text'

var querySpec = navigator.smartstore.buildSmartQuerySpec("select {series:some_field__c} from {series} where {series:some_other_field__c}='some text', 1);

navigator.smartstore.runSmartQuery(querySpec, function(cursor) {                    

I've tried also the following:

var queryString = "select {series:Link_Serie_su_sito_web__c} from {series} where {series:Name}='"+key+"'";

app.seriesCache.find({queryType:"smart", smartSql:queryString, order:"ascending", pageSize:1}).then(function(result){               
        console.log("SMART SQL: "+result.records[0]["Link_Serie_su_sito_web__c"]);

But when I run it in the emulator with the first trial I get:

E/Web Console(2263): com.salesforce.smartstore:pgRunSmartQuery failed at file:///android_asset/www/extlib/cordova.force.js:190

and in the console log I read "undefined"

With the second trial I get nothing on the console (not even an error)

The documentation is quite puzzling about this, have I to declare in the indexes of the soup also some_field__c? Even if I want to use SmartQuery?

Thanks for the assistance, T.

  • Hello, T. Rossi, have you looked at the "Developing Offline-Capable Apps with the Salesforce Mobile SDK and SmartStore" Dreamforce session and the associated sample code? Not sure whether that helps, but it's the most recent reference to SmartStore that I could find. – Marty C. Jul 2 '14 at 0:18
  • That example is not really suiting my scenario, that is a query on a soup created from 0, I have this soup created with the "standard" procedure, the relationship is not very clear, in fact my initial code comes from that example but is not working. – T. Rossi Jul 2 '14 at 15:34
  • Can you check what the javascript debug log is saying? It should tell you in more detail what steps are being taken. – Jolanda Verhoef Sep 18 '14 at 6:26

Better late than never I suppose, but yes, you have to create indexes for all of the fields you want to query by.

So you'd need to create an index on some_field__c in order to filter on it in a SmartSQL query, and yes it's a bit annoying. That said, you can at least change the index specs you have on a soup and re-index the data. From the docs:

The following example demonstrates a simple soup alteration. To start, the developer defines a soup that’s indexed on name and address fields, and then upserts an agent record.

       [{path:'name',type:'string'}, {path:'address', type:'string'}]);

       [{name:'James Bond', address:'1 market st', agentNumber:"007"}]);

When time and experience show that users really wanted to query their agents by "agentNumber" rather than address, the developer decides to drop the index on address and add an index on agentNumber.

    [{path:'name',type:'string'}, {path:'agentNumber', type:'string'}], true);

Note the true parameter at the end, that specified that the existing data should be re-indexed, without this existing records would not be found using a query filtering on agentNumber.

| improve this answer | |
  • hah... next project I'll have no worries:) thanks! – T. Rossi May 8 '15 at 8:43

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.