List Viewのメタデータを取得する


このアイデアを見てMetaData APIを使えば取得できるだろうと思っていましたが、Postmanからは思ったようなメタデータが取得できないですね。

[リスト ビューがまだ表示されていることを確認するために、表示設定が「すべてのユーザーに表示 (パートナーおよびカスタマー ポータル ユーザーを含む)」に設定されている、最近変更されたすべてのケース リスト ビューを表示する単純なレポートがあれば便利です。顧客が見るのに適しています。](https://ideas.salesforce.com/s/idea/a0B8W00000GdXJ1UAN/create-reports-on-list-views)


他に方法がないかと悩んでいましたが、UIのAPIが使えそうです。

+ [Get List Views for an Object](https://developer.salesforce.com/docs/atlas.en-us.uiapi.meta/uiapi/ui_api_resources_list_views_object.htm)

オブジェクトに関連付けられたリスト ビューのコレクションを返します。

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/328136/718a64cc-d8fa-1911-e67d-9260a8b63db9.png)

今回はAccountオブジェクトを指定してみます。

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/328136/9145be54-52fb-5c5d-36f2-632c7ec97826.png)

結果は以下の通りです。

```Json
{
    "count": 6,
    "currentPageToken": "0",
    "currentPageUrl": "/services/data/v60.0/ui-api/list-ui/Account?pageSize=20&pageToken=0",
    "eTag": "a49f70ad56388c3189c11d4e8cb54478",
    "lists": [
        {
            "apiName": "AllAccounts",
            "id": "00B5i00000cCVbgEAG",
            "label": "All Accounts",
            "listUiUrl": "/services/data/v60.0/ui-api/list-ui/Account/AllAccounts"
        },
        {
            "apiName": "MyAccounts",
            "id": "00B5i00000cCVbmEAG",
            "label": "My Accounts",
            "listUiUrl": "/services/data/v60.0/ui-api/list-ui/Account/MyAccounts"
        },
        {
            "apiName": "NewLastWeek",
            "id": "00B5i00000cCVbAEAW",
            "label": "New Last Week",
            "listUiUrl": "/services/data/v60.0/ui-api/list-ui/Account/NewLastWeek"
        },
        {
            "apiName": "NewThisWeek",
            "id": "00B5i00000cCVazEAG",
            "label": "New This Week",
            "listUiUrl": "/services/data/v60.0/ui-api/list-ui/Account/NewThisWeek"
        },
        {
            "apiName": "PlatinumandGoldSLACustomers",
            "id": "00B5i00000cCVbQEAW",
            "label": "Platinum and Gold SLA Customers",
            "listUiUrl": "/services/data/v60.0/ui-api/list-ui/Account/PlatinumandGoldSLACustomers"
        },
        {
            "apiName": "RecentlyViewedAccounts",
            "id": "00B5i00000cCVbfEAG",
            "label": "Recently Viewed Accounts",
            "listUiUrl": "/services/data/v60.0/ui-api/list-ui/Account/RecentlyViewedAccounts"
        }
    ],
    "nextPageToken": null,
    "nextPageUrl": null,
    "objectApiName": "Account",
    "pageSize": 20,
    "previousPageToken": null,
    "previousPageUrl": null,
    "queryString": null,
    "recentListsOnly": false
}
```

Recently Viewedは特別っぽいので、ここの対象にはなってないのかもれませんね。

エンドポイントが別のようです。

+ [Get Most Recently Used List View Metadata](https://developer.salesforce.com/docs/atlas.en-us.uiapi.meta/uiapi/ui_api_resources_mru_list_views_md.htm)

Tooling APIにもエンドポイントがある。

+ [RecentlyViewed](https://developer.salesforce.com/docs/atlas.en-us.api_tooling.meta/api_tooling/tooling_api_objects_recentlyviewed.htm)


![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/328136/f94a1ea4-3c01-3dab-8411-18f2705fe521.png)


これでListViesのIdが分かったので、次にIdを使ってメタデータを取得します。

+ [Get List View Metadata](https://developer.salesforce.com/docs/atlas.en-us.uiapi.meta/uiapi/ui_api_resources_list_views_md.htm)

リストビューのメタデータを返します。

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/328136/648de9fa-7d7a-8481-f3b2-6761cc7da0cc.png)


![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/328136/16d9a8d7-2233-36ec-6491-74b213abda0a.png)

```Json
{
    "cloneable": true,
    "createable": true,
    "deletable": true,
    "displayColumns": [
        {
            "fieldApiName": "Name",
            "label": "Account Name",
            "lookupId": "Id",
            "sortable": true
        },
        {
            "fieldApiName": "Site",
            "label": "Account Site",
            "lookupId": null,
            "sortable": true
        },
        {
            "fieldApiName": "BillingState",
            "label": "Billing State/Province",
            "lookupId": null,
            "sortable": true
        },
        {
            "fieldApiName": "Phone",
            "label": "Phone",
            "lookupId": null,
            "sortable": true
        },
        {
            "fieldApiName": "Type",
            "label": "Type",
            "lookupId": null,
            "sortable": true
        },
        {
            "fieldApiName": "Owner.Alias",
            "label": "Account Owner Alias",
            "lookupId": "Owner.Id",
            "sortable": true
        }
    ],
    "eTag": "c1eaf36fd502359d11ff8342df52c6ab",
    "filterLogicString": null,
    "filteredByInfo": [],
    "label": "All Accounts",
    "listReference": {
        "id": "00B5i00000cCVbgEAG",
        "listViewApiName": "AllAccounts",
        "objectApiName": "Account",
        "type": "listView"
    },
    "orderedByInfo": [
        {
            "fieldApiName": "Name",
            "isAscending": true,
            "label": "Account Name"
        }
    ],
    "updateable": true,
    "userPreferences": {
        "columnWidths": {
            "Site": -1,
            "Type": -1,
            "Owner.Alias": -1,
            "Phone": -1,
            "BillingState": -1,
            "Name": -1
        },
        "columnWrap": {
            "Site": false,
            "Type": false,
            "Owner.Alias": false,
            "Phone": false,
            "BillingState": false,
            "Name": false
        }
    },
    "visibility": "Public",
    "visibilityEditable": true
}
```
ListViewのカラムは取得できている感じです。

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/328136/1754bbdf-97e4-b0cc-40c3-7652c40cf19c.png)

検索条件、共有設定はないのかな。


# Winter'15 ListView API を使用した Super ListView ビューア

古い記事ですが、REST APIがあるのかな？

+ [Super ListView Viewer using Winter’15 ListView API](https://andyinthecloud.com/2014/09/20/super-listview-viewer-using-winter15-listview-api/)

```
{{_endpoint}}/services/data/v{{version}}/sobjects/:SOBJECT_API_NAME/listviews/
```

UI API と内容は似ているけどフォーマットは違う。

```Json
{
    "done": true,
    "listviews": [
        {
            "describeUrl": "/services/data/v60.0/sobjects/Account/listviews/00B5i00000cCVazEAG/describe",
            "developerName": "NewThisWeek",
            "id": "00B5i00000cCVazEAG",
            "label": "New This Week",
            "resultsUrl": "/services/data/v60.0/sobjects/Account/listviews/00B5i00000cCVazEAG/results",
            "soqlCompatible": true,
            "url": "/services/data/v60.0/sobjects/Account/listviews/00B5i00000cCVazEAG"
        },
        {
            "describeUrl": "/services/data/v60.0/sobjects/Account/listviews/00B5i00000cCVbAEAW/describe",
            "developerName": "NewLastWeek",
            "id": "00B5i00000cCVbAEAW",
            "label": "New Last Week",
            "resultsUrl": "/services/data/v60.0/sobjects/Account/listviews/00B5i00000cCVbAEAW/results",
            "soqlCompatible": true,
            "url": "/services/data/v60.0/sobjects/Account/listviews/00B5i00000cCVbAEAW"
        },
        {
            "describeUrl": "/services/data/v60.0/sobjects/Account/listviews/00B5i00000cCVbQEAW/describe",
            "developerName": "PlatinumandGoldSLACustomers",
            "id": "00B5i00000cCVbQEAW",
            "label": "Platinum and Gold SLA Customers",
            "resultsUrl": "/services/data/v60.0/sobjects/Account/listviews/00B5i00000cCVbQEAW/results",
            "soqlCompatible": true,
            "url": "/services/data/v60.0/sobjects/Account/listviews/00B5i00000cCVbQEAW"
        },
        {
            "describeUrl": "/services/data/v60.0/sobjects/Account/listviews/00B5i00000cCVbfEAG/describe",
            "developerName": "RecentlyViewedAccounts",
            "id": "00B5i00000cCVbfEAG",
            "label": "Recently Viewed Accounts",
            "resultsUrl": "/services/data/v60.0/sobjects/Account/listviews/00B5i00000cCVbfEAG/results",
            "soqlCompatible": true,
            "url": "/services/data/v60.0/sobjects/Account/listviews/00B5i00000cCVbfEAG"
        },
        {
            "describeUrl": "/services/data/v60.0/sobjects/Account/listviews/00B5i00000cCVbgEAG/describe",
            "developerName": "AllAccounts",
            "id": "00B5i00000cCVbgEAG",
            "label": "All Accounts",
            "resultsUrl": "/services/data/v60.0/sobjects/Account/listviews/00B5i00000cCVbgEAG/results",
            "soqlCompatible": true,
            "url": "/services/data/v60.0/sobjects/Account/listviews/00B5i00000cCVbgEAG"
        },
        {
            "describeUrl": "/services/data/v60.0/sobjects/Account/listviews/00B5i00000cCVbmEAG/describe",
            "developerName": "MyAccounts",
            "id": "00B5i00000cCVbmEAG",
            "label": "My Accounts",
            "resultsUrl": "/services/data/v60.0/sobjects/Account/listviews/00B5i00000cCVbmEAG/results",
            "soqlCompatible": true,
            "url": "/services/data/v60.0/sobjects/Account/listviews/00B5i00000cCVbmEAG"
        }
    ],
    "nextRecordsUrl": null,
    "size": 6,
    "sobjectType": "Account"
}
```
以下で、詳細を取ることができますが、共有設定はやっぱりないな。

```
{{_endpoint}}/services/data/v{{version}}/sobjects/:SOBJECT_API_NAME/listviews/:LIST_VIEW_ID/results
```

検索内容は取得できます。

```Json
    "query": "SELECT Name, Site, BillingState, Phone, toLabel(Type), Owner.Alias, Id, CreatedDate, LastModifiedDate, SystemModstamp, Owner.Id, OwnerId FROM Account USING SCOPE mru ORDER BY Name ASC NULLS FIRST, Id ASC NULLS FIRST",
    "relatedEntityId": null,
    "scope": "mru",
    "scopeEntityId": null,
    "sobjectType": "Account",
    "whereCondition": {
        "conditions": [],
        "conjunction": "and"
```


# 共有設定

+ [Export List views with Shared To details](https://jayakrishnasfdc.wordpress.com/2019/02/24/export-list-views-with-shared-to-details/)