+ Start a Discussion
Mike @ BlackTabMike @ BlackTab 

Parse ListView Filters for use in SOQL

I need a way for a user to pick any ListView they created, and turn it into a SOQL statement. Is this possible? If so, what would it take to do it?


Hi Mike,


Did you solved this issue. I am also looking for same thing.... If solved, Please help me..





Me three please let me know
David van t HooftDavid van t Hooft
You can read the Listview filters by reading the meta data using the MetadataService.cls (financial force google for it) then use the code like:
  * Create a metadata service to get access to the metadata
  * @return MetadataService.MetadataPort
public MetadataService.MetadataPort createService() {
  MetadataService.MetadataPort service = new MetadataService.MetadataPort();
  service.SessionHeader = new MetadataService.SessionHeader_element();
  service.SessionHeader.sessionId = UserInfo.getSessionId();
  return service; 

     * read the listview object to read the listview metadata
     * only do this ones during its livecycle
public void readListViews() {
  if (this.listViews==null) {
   MetadataService.MetadataPort service = createService();
   this.listViews =
    ((MetadataService.CustomObject) service.readMetadata('CustomObject',
     new String[] { 'MyListView' }).getRecords()[0]).listViews;

And of course you need to parse the filters and filter logic using the MetadataService.cls.

Good luck