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.
.../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.