function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
logontokartiklogontokartik 

ListView in Apex Code or Visualforce Page

Hello,

 

I have a requirement where I need to display the columns seleted / defined for a particular listview in a custom visualforce page. 

I know that there is a property ListView. Columns in Metadata API for Salesforce, but I am not sure on how to use it in APEX Code.

Can anyone please help me with regard to this ?? Any examples on how to use this are appreciated.

 

Thanks.

Kartik

hitzhitz

Hi Karitk,

 

hi use below code

 

 

<!-- Page: -->                    

<apex:page controller="dataTableCon" id="thePage">

        <apex:dataTable value="{!accounts}" var="account" id="theTable" rowClasses="odd,even"

                        styleClass="tableClass">

                <apex:facet name="caption">table caption</apex:facet>

                <apex:facet name="header">table header</apex:facet>

                <apex:facet name="footer">table footer</apex:facet>

                <apex:column>

                        <apex:facet name="header">Name</apex:facet>

                        <apex:facet name="footer">column footer</apex:facet>

                        <apex:outputText value="{!account.name}"/>

                </apex:column>

                <apex:column>

                        <apex:facet name="header">Owner</apex:facet>

                        <apex:facet name="footer">column footer</apex:facet>

                        <apex:outputText value="{!account.owner.name}"/>

                </apex:column>

        </apex:dataTable>

</apex:page>

                        

/*** Controller: ***/

                        

public class dataTableCon {

                        

        List<Account> accounts;



        public List<Account> getAccounts() {

                if(accounts == null) accounts = [select name, owner.name from account limit 10];

                return accounts;

        }

}

 

logontokartiklogontokartik

Hi Hitesh,

I am not sure if you got my question, I am trying to get the LISTVIEW columns into my apex code, so that I can programatically dynamically change the LISTVIEWS from apex code.

mtbclimbermtbclimber
The columns specified for one specific listview are not exposed in a way that is accessible from Apex. I recommend checking out FieldSets for your use case. If you simply need to expose non-hard coded fields into your page and standardsetcontroller can give you what you need then it may be a solution for you. There may also be a way to pass this into apex but I'd like to verify with the Product Manager before having you go down that path.
Raj_0202Raj_0202

Hi Andrew

 

We want to create a custom account list similar to Salesforce out of the box account list page. We are able to filter the records in our table on the basis of list views(with the help of filter ID). But we would also like to get the columns dynamically from the list views. Is there a way to get the columns from each list views?

 

Your quick response would really help us in moving forward. Thanks in advance.

 

Raj

 

AmanAman

 

Hi Kartik,

 

I also need the same thing to dynamically display the columns of the selected view. Did you get your answer from anywhere. If yes, please help me.

 

Regards,

Aman

Ulas KutukUlas Kutuk

Hi Kartik,

I wanna ask you, did you find any solution for this post ? I also need to get listviews in apex to display fully customized VF page.

I just wonder is it possible or not ?

Thanks.

nagalakshminagalakshmi

Hi Karthik,

 

Did you solve this issue. I am also looking for the same thing. I am able to display one object list view with corresponding records in visual force page. But i want to display account,contact,lead list views in the same picklist. If your issue solved please help me.

 

This is my code

 

<apex:page standardController="Account" recordSetvar="accounts">
  <apex:pageBlock title="Viewing Accounts">
  <apex:form id="theForm">
    <apex:panelGrid columns="2">
      <apex:outputLabel value="View:"/>
      <apex:selectList value="{!filterId}" size="1">
        <apex:actionSupport event="onchange" rerender="list"/>
        <apex:selectOptions value="{!listviewoptions}"/>
      </apex:selectList>
    </apex:panelGrid>
    <apex:pageBlockSection >
      <apex:dataList var="a" value="{!accounts}" id="list">
        {!a.name} </apex:dataList>
    </apex:pageBlockSection>
  </apex:form>
  </apex:pageBlock>
 
 
 
 
 <!-- <apex:pageBlock title="Viewing Contacts">
  <apex:form id="theForm">
    <apex:panelGrid columns="2">
      <apex:outputLabel value="View:"/>
      <apex:selectList value="{!filterId}" size="1">
        <apex:actionSupport event="onchange" rerender="list"/>
        <apex:selectOptions value="{!listviewoptions}"/>
      </apex:selectList>
    </apex:panelGrid>
    <apex:pageBlockSection >
      <apex:dataList var="a" value="{!account.contacts}" id="list">
        {!a.name} </apex:dataList>
    </apex:pageBlockSection>
  </apex:form>
  </apex:pageBlock>
   <apex:ListViews type="Contact" />-->
 
</apex:page>

 

Thanks,

Lakshmi.

logontokartiklogontokartik

You either need to use the Metadata API wsdl in your APEX Code. Please see below link

 

Metadata API

 

OR

 

Use the fieldsets and retrieve the fieldsets using APEX for multiple objects.

Arun Garg 9Arun Garg 9
Hi ,
Read this link to display account list view in lightning and insert account.
https://sfdcadda.blogspot.in/2017/05/insert-account-and-show-list-view-of.html