3

During my work on this question, I'm trying to retrieve a ListView using this code:

public class SFSEMetadataListView {
    public static void readListView() {
        MetadataService.MetadataPort            service         = createService();
        MetadataService.ListView                listView        = (MetadataService.ListView) service.readMetadata(
            'ListView', new String[] { 'Lead.MyListView' }
        ).getRecords()[0];
        System.Debug(JSON.serializePretty(listView));
        if(listView.columns!=null)
            for(String column : listView.columns)
                System.Debug('Column ' + column)
        ;
        if(listView.filters!=null)
            for(MetadataService.ListViewFilter filter : listView.filters)
                System.Debug('Filter ' + filter.field + ' ' + filter.operation + ' ' + filter.value)
        ;
    }
    public static MetadataService.MetadataPort createService() {
        MetadataService.MetadataPort            service         = new MetadataService.MetadataPort();
            service.SessionHeader               = new MetadataService.SessionHeader_element();
            service.SessionHeader.sessionId     = UserInfo.getSessionId();
        return service;
    }
}

1) Restricted Visibility

Why ListViews saved "Visible only to me" don't get retrieved and those saved "Visible for all users" actually do get retrieved? How to get "Restricted" ListViews, too?

enter image description here

2) Duplicate result properties

Now in case of "Visible for all users" there is a usable result, however the output of System.Debug(JSON.serializePretty(listView)) is puzzling:

17:38:29.538 (538524558)|USER_DEBUG|[221]|WARN|{
   "fullName" : null,
   "field_order_type_info" : [ "fullName" ],
   "type_att_info" : [ "xsi:type" ],
   "type" : "ListView",
   "sharedTo" : null,
   "queue" : null,
   "language" : null,
   "label" : "MyListView",
   "fullName" : "Lead.MyListView",
   "filterScope" : "Everything",
   "filters" : [ {
      "value" : "a",
      "operation" : "contains",
      "field_order_type_info" : [ "field", "operation", "value" ],
      "field" : "FULL_NAME",
   } ],
   "field_order_type_info" : [ "fullName", "booleanFilter", "columns", "division", "filterScope", "filters", "label", "language", "queue", "sharedTo" ],
   "division" : null,
   "columns" : [ "FULL_NAME", "LEAD.COMPANY", "LEAD.STATE", "LEAD.EMAIL", "LEAD.STATUS", "LEAD.CREATED_DATE", "CORE.USERS.ALIAS", "LEAD.UNREAD" ],
   "booleanFilter" : null,
} 

The member fullName and field_order_type_info seem to appear twice and I can't explain how this is possible. However listView.fullName outputs 'Lead.MyListView' as expected. Any ideas?

3
  1. It is not possible to retrieve personal list views by any means AFAIK. They do not seem to be saved to the ListView object you access via Metadata API. This holds true if you are accessing ListViews through ApexPages.StandardSetController as well. Even when a User creates such personal views, they cannot access their own programatically.

  2. If you look at the Documentation for the MetadataService.ListView type, those properties are enumerated only once (more would cause a compile error), so that sounds more like an issue with the serialization engine. Have you tried plain JSON.serialize?

| improve this answer | |
2

Looks like this is now supported by instantiating the sharedTo property.

It's also possible to retrieve private listviews if the FullName is known.

  • Deploy "Visible to all users" (Includes partner and customer portal users)

    listview.sharedTo = null
    
  • Deploy "Visible only to me"

    listview.sharedTo = new SharedTo(
        role = null,
        roles = null,
        queue = null,
        groups = null,
        managers = null,
        territory = null,
        groupNames = null,
        portalRole = null,
        territories = null,
        allPartnerUsers = null,
        allInternalUsers = null,
        managerSubordinates = null,
        channelProgramGroup = null,
        roleAndSubordinates = null,
        channelProgramGroups = null,
        rolesAndSubordinates = null,
        allCustomerPortalUsers = null,
        territoryAndSubordinates = null,
        portalRoleAndSubordinates = null,
        territoriesAndSubordinates = null,
        roleAndSubordinatesInternal = null
    }
    
| improve this answer | |
  • Interesting approach. However, even though when you edit the list view it says "Visible only to me", other users can still see that list view... Is there anything specific I need to do in addition to the above? – Boris Bachovski May 14 '18 at 6:31
  • @BorisBachovski Oh wow :( no idea – bigassforce May 15 '18 at 7:05

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.