Get Listview Records | Listview filters and Query in Apex

cafeforce
cafeforce 8k Views 11 comments

Sometimes it is very needed to get Listview records. But what if you get all Listview fields and filters. With this method you can get listview fields, filter, sorting order and even query too.

This method uses the REST API to make a callout and fetch the listview data. To get all these listview data you need to pass listview Id and sObject name to it. Listview Id can be easily fetched by querying on Listview object. You can use the below query to get Listview Id.

Here you can pass your listview name in the WHERE condition of the query to get your specific listview Id. You also need to pass your session Id into it as it is s REST API callout.

Here, to get another data you need to iterate tokenResponse variable. This variable will provide you the below data.

get listview records query filters and fields

So this way you can easily fetch Listview records, fields, filters, and query. Also, the sort filters.

If you want to get records directly, you can use the below endpoint in this method. But fetching records using this have some limits. You can check out more information here.

 

Also Check:

For any queries or suggestions, comment below.

Cheers … Happy Coding … 🙂

Share This Article
11 Comments
Subscribe
Notify of
guest

11 Comments
Oldest
Newest
Inline Feedbacks
View all comments
Mohammad Imran

In the Get Listview Records | Listview filters and Query in Apex, how can I use it on visual force page and get the related items from this list view?

SHUBHAM

getting Unauthorised error 401

Last edited 3 years ago by SHUBHAM
Shamikh

I am also getting getting Unauthorised error 401. Strangely the method works fine from Anonymous block but when i am invoking from my LWC it is throwing error

Nikhil Garg

I’m also getting the same error but don’t know how to resolve it. Could you please share some useful resource.

Nikhil Garg

But my LWC component is working fine on the local development server it is not showing the records when I deploy it to my org

John S.

Hello,

I’m using the same Apex code you posted called from an LWC and I’m getting the server response Unauthorized, StatusCode 401. I printed the SessionId to the debug logs and it seems to be defined, it shows a long string of letters and numbers. Do you have any suggestions on how to get rid of the error?