Activity › Forums › Salesforce® Discussions › How can I fetch the list views columns in Salesforce?
-
How can I fetch the list views columns in Salesforce?
Posted by Naman on April 30, 2016 at 6:07 PMI want to fetch the list views columns in salesforce. Please tell how to do this.
Ajay Prakash replied 8 years, 3 months ago 3 Members · 2 Replies -
2 Replies
- [adinserter block='9']
-
We can retrieve list view column or the records based on the list view id using HTTP request. The response contains the query string that contains columns of the list view. Below code is for reference –
public static List<Account> getFilteredAccounts(String filterId){ HttpRequest req = new HttpRequest(); String baseUrl = URL.getSalesforceBaseUrl().toExternalForm(); String endPoinURL = baseUrl+’/services/data/v32.0/sobjects/Account/listviews/’+filterId+’/describe’; req.setEndpoint(endPoinURL); req.setMethod(‘GET’); req.setHeader(‘Authorization’, ‘Bearer ‘ + UserInfo.getSessionId()); Http http = new Http(); HTTPResponse response = http.send(req); Map<String, Object> tokenResponse = (Map<String, Object>) JSON.deserializeUntyped(response.getBody()); String query = (String) tokenResponse.get(‘query’); List<Account> AccountList = new List<Account>(); for(Account accountObj : database.query(query)){ AccountList.add(accountObj); } return AccountList; }In the above example, I have retrieved accounts based on the selected list view.
Log In to reply.