[SalesForce] Access ListView via REST API

I am trying to use the REST api to access Opportunities in SalesForce. I seem to be able to do this quite easily with a call to services/data/v26.0/sobjects/Opportunity/ and enumerating over the recentItems member of the returned object. What I'd like to be able to do is two fold, first get the list of filters that can be applied to Opportunities, eg "All Opportunities", "Active Opportunities" or whatever a user defines. The datatype description can be found here (http://na14.salesforce.com/help/doc/en/customviews.htm). Is this information accessible via the REST API (preferable) or the SOAP API or do I have to do something else to get the information?

Code sample:

var instance = "https://na14.salesforce.com/";
var accessToken = "*RemovedForSecurity*";

var url = new UriBuilder(instance + "services/data/v26.0/sobjects/Opportunity/").Uri;
using (var httpClient = new HttpClient())
{
    httpClient.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", "Bearer " + accessToken);
    using (var stream = await httpClient.GetStreamAsync(url))
    {
        var sobjects = new JsonSerializer().Deserialize<ExpandoObject>(new JsonTextReader(new StreamReader(stream)));
        foreach(var sobject in sobjects)
        {
            Console.WriteLine(sobject);
        }
    }
}

Best Answer

The answer you're looking for here found here: rest - How to retrieve list views of any salesforce object using API?. In short, the answer is, you'll have to use the Metadata API to get a full list of publicly accessible list views (those not set to "Only me"), or you'll have to construct some Apex Code that utilizes the StandardSetController to get a list of list view ID values and names (via getListViewOptions()). There's no convenient API that exposes all views available to a user directly. The most robust option, assuming you need to know the actual filters from the list view would be to use the Metadata API. You'll need a way to read and write ZIP files and XML files.

Related Topic