Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

I'm creating a sync engine for a mobile app, and I want to get meta data about the state of a whole lot of different objects in as few API calls as possible. Is it possible to pass more than one SOQL statements in one API call or otherwise combine them? Or would I need to create an Apex class to integrate these different result sets into one Json? Is there a better way?

share|improve this question
1  
The Chatter REST API provides a generic way to combine multiple REST calls into one (see salesforce.com/us/developer/docs/chatterapi/Content/…), but the feature isn't available in the Salesforce REST API yet. –  alouie Mar 9 at 0:18
add comment

1 Answer 1

up vote 3 down vote accepted

Perhaps one of the standard APIs can do this - if so hopefully someone will post that answer.

As far as creating your own class, this code compiles:

@RestResource(urlMapping='/query')
global with sharing class Reader {
    @HttpPost
    global static List<List<SObject>> post(List<String> soqls) {
        List<List<SObject>> results = new List<List<SObject>>();
        for (String soql : soqls) {
            results.add(Database.query(soql));
        }
        return results;
    }
}

and in theory will return the query results for each SOQL string passed in with the platform taking care of the serialization (to JSON or XML) using its default algorithms.

But if you care about the URL patterns part of REST, using a POST to just GET data is inappropriate. If you don't need to pass the SOQL in, you can of course hard code the SOQL in the class and just use a GET.

share|improve this answer
1  
Custom Apex REST is definitely the way to go. And then you can also create a custom data structure as an Apex class and return that as you data type. So you can combine whatever information you need. –  joshbirk Mar 5 at 20:36
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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