0

I need to get the tasks that are stored in list views that are selected by the user. I've tried a couple things that I'll outline below:

HTTP API request

I've tried making a REST API call to get the metadata for the listviews, but I've never managed to get anything but a 401 Unauthorized error in the response. I slightly modified the code suggested here:

HttpRequest req = new HttpRequest(); 
String baseUrl = URL.getSalesforceBaseUrl().toExternalForm(); 
String endPointURL = baseUrl+'/services/data/v54.0/sobjects/Task/listviews/' + listViews[0].get('Id') +'/describe';
req.setEndpoint(endPointURL);
req.setMethod('GET'); req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionId());
System.debug(UserInfo.getSessionId().SubString(15));    // SessionID seems to exist 
Http http = new Http(); 
HttpResponse response = http.send(req);
System.debug(response);     // prints System.HttpResponse[Status=Unauthorized, StatusCode=401]

uiListApi and uiListsApi wire adapters

uiListApi is deprecated and should not be used in production, but I tried it anyway just to see what the result would be and it gave me "Object Task is not supported in UI API". Reading this documentation page makes it seem as though all the wire adapters listed will not work for objects not supported by the UI API (including Tasks). I tried uiListsApi anyway despite this, but even copying the code from the documentation which used Accounts instead of Tasks, it would just return an empty object. It might be an issue with the data in my org but I'm not sure.

Does anyone have any suggestions on other methods I should try? It seems like you might be able to put a Visualforce page in an iframe within the LWC, then call getListViewOptions() on the StandardSetController for that to get the list view data, but that seems like a hacky solution and I'm wondering if there's anything else I can do.

2
  • It sounds like you want .../listviews/<viewid>/results rather than .../describe - see doc. Make sure that the privileges underlying your session ID are enough for this API call to work.
    – identigral
    Commented May 16, 2022 at 19:27
  • Thanks for your reply. It turned out that the session IDs you get in lightning with UserInfo.getSessionId() don't have permissions to do any API calls, so I'm trying to use a named credential instead.
    – John S.
    Commented May 18, 2022 at 17:40

1 Answer 1

0

The User Interface API is what you need. This is a link to the operations specifically dealing with List Views, including fetching records:

https://developer.salesforce.com/docs/atlas.en-us.uiapi.meta/uiapi/ui_api_resources_list_views.htm

1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented May 16, 2022 at 22:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .