2

I'm using the SalesforceMobileSDK and I'm having trouble querying my smartstore soup in my native android application. When I query my soup I recieve a JSONArray with JSONArrays in it, while it has to be filled with JSONObjects. I think this is because I'm using the "buildSmartQuerySpec" function from the QuerySpec class.

Is it normal that the "buildSmartQuerySpec" returns a JSONArray with JSONArrays in it, which normally should be a JSONArray with JSONObjects?

This is my function to retrieve a JSONArray filled with the smartstore soup:

public JSONArray fetchOfflineLeads(){
   JSONArray result = null;
   if(smartStore.hasSoup(LEADS_SOUP)){

      result = query("SELECT {Lead:Name}, {Lead:Company} FROM {Lead}");
      System.out.println(result);

  }else{
      System.out.println("there is no soup");
      return null;
  }
  return result;
}

This is my query function :

public JSONArray query(String smartSql){
    JSONArray result = null;

    QuerySpec querySpec = QuerySpec.buildSmartQuerySpec(smartSql, 10);
    int count = smartStore.countQuery(querySpec);

    querySpec = QuerySpec.buildSmartQuerySpec(smartSql, count);

    try{
        result = smartStore.query(querySpec, 0);
    }catch(JSONException e){
        Log.e(TAG, "Error when trying to run query");
    }
        return result;
    }

I get this when I print my JSONArray out:

[["Bertha Boxer","Farmers Coop. of Florida"],["Phyllis Cotton","Abbott Insurance"],["Jeff Glimpse","Jackson Controls"]]

While it has to be like this:

[{"Name":"Bertha Boxer","Company":"Farmers Coop. of Florida"},{"Name":"Phyllis Cotton","Company""Abbott Insurance"},{"Name":"Jeff Glimpse","Company""Jackson Controls"}]

Someone knows what I'm doing wrong? Is my string with my smartSql not right?

  • Is this related to Salesforce? There may be a better forum for this question. – Doug B Jun 12 '15 at 9:28
  • Looks to be using the SF mobile SDK. – Samuel De Rycke Jun 12 '15 at 9:37
1

Based on the syntax table in the Mobile SDK docs, try changing your smartSql to:

result = query("SELECT {Lead:_soup} FROM {Lead}");

Note that this should return the entire JSON Lead object, and not an object with only specific fields. I don't believe you can return arbitrary JSON objects containing only certain field from the originally stored object(s).

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.