1

here is the class:

public with sharing class Paginationmin1
{

    public String listFilterId {get; set;}
    Public Integer noOfRecords {get; set;}
    Public Integer size {get; set;}
    //public List <SelectOption> paginationSizeOptions {get; set;}
    /*public Paginationmin1()
    {
        paginationSizeOptions = NEW List<SelectOption>();
        paginationSizeOptions.add(NEW SelectOption('5','5'));
        paginationSizeOptions.add(NEW SelectOption('10','10'));
        paginationSizeOptions.add(NEW SelectOption('20','20'));
        paginationSizeOptions.add(NEW SelectOption('50','50'));
    }
    */
    public ApexPages.StandardSetController setCon
     {
        get
        {
            if(setCon == null)
            {
                size = 10;
                string queryString = 'SELECT Name, Account.Name, Title, Phone, Email, Owner.Alias FROM Contact Order By Name LIMIT 100';                                                                                    
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator(queryString));
                setCon.setPageSize(size);
                noOfRecords = setCon.getResultSize();

                //listFilterId = setCon.getFilterId();

            }
            setCon.setFilterId(listFilterId);
                System.debug('--------'+listFilterId);
            return setCon;
        }
        set;
    }

    Public List <Contact> getContacts()
    {
        List<Contact> conList = NEW List<Contact>();
        for(Contact c : (List <Contact>)setCon.getRecords())
        {
            conList.add(c);
        }
        return conList;
    }
    public List <SelectOption> getContactExistingViews()
    {
        return setCon.getListViewOptions();
    }

    public pageReference refresh() 
    {
        setCon = null;
        getContacts();
        setCon.setPageNumber(1);
        return null;
    }
}

this is the VF page:

<apex:page controller="Paginationmin1"  tabStyle="Contact">
    <apex:form >
        <apex:pageBlock id="pb">
            <apex:pageBlockSection >   
                  <apex:pageBlockSectionItem >   
                      <apex:outputLabel value="Use Existing View" />   
                          <apex:selectList value="{!listFilterId}" size="1">    
                              <apex:selectOptions value="{!ContactExistingViews}">
                              </apex:selectOptions>    
                          </apex:selectList>    
                      </apex:pageBlockSectionItem>             
                          <apex:commandButton value="Go!" style="margin: 1em; width: 3em;" />
          </apex:pageBlockSection>           
          <apex:pageBlockTable value="{!Contacts}" var="con">
                <apex:column headerValue="Name">
                    <apex:outputLink value="/{!con.Name}">{!con.Name}
                    </apex:outputLink>                   
                </apex:column>
                <apex:column headerValue="Account Name">
                    <apex:outputLink value="/{!con.Account.Name}">{!con.Account.Name}
                    </apex:outputLink>                   
                </apex:column>
                <apex:column value="{!con.Title}"/>
                <apex:column value="{!con.Phone}"/>
                <apex:column value="{!con.Email}"/>
                <apex:column headerValue="Contact Owner Alias">
                    <apex:outputLink value="/{!con.Owner.Alias}">{!con.Owner.Alias}
                    </apex:outputLink>                   
                </apex:column>
            </apex:pageBlockTable>
                <apex:panelGrid columns="7">
                    <apex:commandButton status="fetchStatus" reRender="pb" value="|<" action="{!setCon.first}" disabled="{!!setCon.hasPrevious}" title="First Page"/>
                    <apex:commandButton status="fetchStatus" reRender="pb" value="<" action="{!setCon.previous}" disabled="{!!setCon.hasPrevious}" title="Previous Page"/>
                    <apex:commandButton status="fetchStatus" reRender="pb" value=">" action="{!setCon.next}" disabled="{!!setCon.hasNext}" title="Next Page"/>
                    <apex:commandButton status="fetchStatus" reRender="pb" value=">|" action="{!setCon.last}" disabled="{!!setCon.hasNext}" title="Last Page"/>
                    <apex:outputText >{!(setCon.pageNumber * size)+1-size}-{!IF((setCon.pageNumber * size)>noOfRecords, noOfRecords,(setCon.pageNumber * size))} of {!noOfRecords}</apex:outputText>
                    <apex:commandButton status="fetchStatus" reRender="pb" value="Refresh" action="{!refresh}" title="Refresh Page"/>
                    <apex:outputPanel style="color:#4AA02C;font-weight:bold">
                        <apex:actionStatus id="fetchStatus" startText="Fetching..." stopText=""/>
                    </apex:outputPanel>
                </apex:panelGrid>
            </apex:pageBlock>
    </apex:form>
</apex:page>

I am not getting how to write that query in this class ?Please give me some example code.I need to create VF page which looks like and has same functionality as listview page

1

I'm using Rest API. https://eu11.salesforce.com - my sandbox.
Test_Object__c - custom object with list view.
00B0Y000005oWV9UAM - list view ID.
Entire query you can find in the response body "query".

HttpRequest req = new HttpRequest();
req.setEndpoint('https://eu11.salesforce.com/services/data/v32.0/sobjects/Test_Object__c/listviews/00B0Y000005oWV9UAM/describe');
req.setMethod('GET');
req.setHeader('Authorization',  'Bearer ' + UserInfo.getSessionId());

Http http = new Http();
HTTPResponse res = http.send(req);
System.debug(res.getBody());

// "query":"SELECT Name, Id, CreatedDate, LastModifiedDate, SystemModstamp FROM Test_Object__c USING SCOPE mine WHERE (Owner.Alias = '123' OR Owner.LastName != 'test') AND Name = '45' ORDER BY Name ASC NULLS FIRST, Id ASC NULLS FIRST"
0

A list view is simply a query with filters applied to it and the fields to be displayed specified. That means you're specifying which fields you want returned along with the WHERE conditions that are the filters specified for your list view.

You need to add a getter Method to retrieve your WHERE conditions such as "Name Like" or Starts With", Last Modified Date, Last Week, My Contacts (OwnerId), etc. You can do those as a drop down in a SelectList if you want for things you've preconfigured or with a text entry or both. If text entry, you'll need to parse it to look for the keywords to convert it to SOQL language you can use. As in "Like" become %string% and "Starts With" becomes %string. RegEx and matcher class methods is good for doing those types of things. I'm confident you'll find lots of posts in the forum on SelectLists as well as in the Visualforce Documentation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.