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
kartik_salesforcekartik_salesforce 

Display List View on Cust. VF Page

Hi

 

I have a Custom Page which is based on Contact Object. Now I need to display Views which are on Standard Contact Pageon Custom VF Page . I should also be able to Edit and Create new Views just like in  Standard page Process. The problem is If I use Standard Controller= "Contact" and Extensions= "Custom_Pagination" I get an error on StandardsetController in apex code. Kindly help me in this plssss

 

VF Page:

<apex:page controller="Custom_Pagination">
<style type="text/css">
.loadingIcon {
background-image: url(/img/loading.gif);
width: 16px;
height: 16px;
}

</style>
<script type="text/javascript">
function checkClicked(){
var isChecked = false;
var inputElem = document.getElementsByTagName("input");
for(var i=0; i<inputElem.length; i++){
if(inputElem[i].checked){
isChecked = true;
}
}
if(isChecked){callMe();}
else{
alert('Please select at least one Contact');
return false;
}
}
function checkAll(cb,cbid)
{
var inputElem = document.getElementsByTagName("input");
for(var i=0; i<inputElem.length; i++)
{

if(inputElem[i].id.indexOf(cbid)!=-1){
inputElem[i].checked = cb.checked;
}
}
}
function highlight (word) {
//alert('1');
document.getElementById (word.id).style.backgroundColor="#8DEEEE"
// alert('1');
}
function dehighlight (word) {
//alert('1');
document.getElementById (word.id).style.backgroundColor="#FFFFFF"
// alert('1');
}
</script>
<apex:form id="form">
<br/>
<div style="align:right;">
<apex:repeat value="{!alphabet}" var="a">
<apex:commandLink id="sample" value="{!a}" action="{!refreshList2}" rerender="block,block2" onmouseout="dehighlight(this);" onmouseover="highlight(this);" style="text-decoration:none;" status="stat">
<apex:param name="alpha" value="{!a}"/>
</apex:commandLink>
<apex:outputLabel style="color : #CCC;">&nbsp;|&nbsp;</apex:outputLabel>
</apex:repeat>
</div>
<br/>
<apex:pageBlock id="block">
<apex:pageBlockButtons location="top" >
<apex:commandButton value="Generate Email" onclick="checkClicked();" reRender="msg"/>
<apex:actionFunction name="callMe" action="{!selectTemplate}"/>
<apex:commandButton rendered="{!standardsetcon.hasprevious}" value="Previous" action="{!standardsetcon.previous}" rerender="block,block2" status="stat"/>
<apex:commandButton rendered="{!standardsetcon.hasnext}" value="Next" action="{!standardsetcon.next}" rerender="block,block2" status="stat"/>

</apex:pageBlockButtons>
<apex:actionStatus id="stat">
<apex:facet name="start">
<apex:outputPanel layout="block" styleClass="message infoM4">
<apex:panelGrid columns="2" styleClass="messageTable" columnClasses="messageCell" style="padding:0px;margin:0px;">
<apex:panelGroup >
<img class="loadingIcon" src="/s.gif"/>
</apex:panelGroup>
<apex:panelGroup >
<div class="messageText">Please wait...</div>
</apex:panelGroup>
</apex:panelGrid>
</apex:outputPanel>
</apex:facet>
<apex:facet name="stop">
<apex:pageBlockTable value="{!CurrentList}" var="c" id="table">
<apex:column >
<apex:facet name="header"><apex:inputcheckbox onclick="checkAll(this,'check')" value="{!fals}" /></apex:facet>
<apex:inputcheckbox value="{!c.checked}" id="check"/>
</apex:column>
<apex:column value="{!c.ocontact.name}" headerValue="Name"/>
<apex:column value="{!c.ocontact.AccountId}" headerValue="Account"/>
<apex:column value="{!c.ocontact.phone}" headerValue="Phone"/>
<apex:column value="{!c.ocontact.Email}" headerValue="Email"/>
<apex:column value="{!c.ocontact.Email_1__c}" headerValue="Email one"/>
<apex:column value="{!c.ocontact.Status__c}" headerValue="Status"/>
</apex:pageBlockTable>
</apex:facet>
</apex:actionStatus>
</apex:pageBlock>
</apex:form>
</apex:page>

 

Controller:

--------------

public with sharing class Custom_Pagination {

public String templates { get; set; }
public List<emailtemplate> searchedTemplate;
public List<emailtemplate> getSearchTemp(){return searchedTemplate; }
private static List<EmailTemplate> allEmailTemplates = new List<EmailTemplate>() ;
private static List<Folder> allEmailTemplateFolders = new List<Folder>() ;
public String selectedEmailTemplateFolder {public get; public set;}
public String selectedEmailTemplate {public get; public set;}
public EmailTemplate chosenEmailTemplate {public get; private set;}
public PageReference renderTemplate() {
searchedTemplate = [select id,name, subject, body from EmailTemplate where id=:templates];
return null;
}

public List<SelectOption> getemailTemplates(){
List<SelectOption> options = new List<SelectOption>();
List<EmailTemplate> et = [select id,name, subject, body from EmailTemplate];
for( EmailTemplate f : et)
{
options.add(new SelectOption(f.Id, f.Name));
}
return options;
}

public PageReference checkType() {
if(template=='Outlook'){
return new PageReference('/apex/generateCsv');
}
else if(template=='SFDC Template'){
return new PageReference('/apex/Select_Email_Template');
}
return null;
}
public PageReference B() {
/* your action here */
return new PageReference('/apex/generateCsv');
}
public PageReference A() {
/* your action here */
return new PageReference('/apex/Generate_Document');
}
public PageReference C() {
/* your action here */
return new PageReference('/apex/Mass_Mail_Contact');
}
public String template;

public String gettemplate(){
return template;
}

public void settemplate(String template){
this.template = template;
}

public PageReference selectTemplate() {
return new PageReference('/apex/Mass_Mail_Comm_Type');
}



private List<contactSet> contactSetList{get;set;}
private string contactListQuery;
private set<contact> selectedContact;

public List<string> alphabet{get;set;}
public boolean fals{get;set;}

public Custom_Pagination(){
fals=false;
alphabet=new string[]{'All','A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };
contactSetList = new List<contactSet>();
selectedContact = new set<contact>();
contactListQuery= 'select id,name,phone,Email,Email_1__c,AccountId,Status__c from contact limit 1000';
//allEmailTemplates = [select Id, Name, Subject, Body, FolderId from EmailTemplate limit 100];
//allEmailTemplateFolders = [select Id, Name from Folder where Type = 'Email'];
}

Private void updateSelectedContact(){
for(contactSet cs:contactSetList ){
if(cs.checked)
selectedcontact.add(cs.ocontact);
else{
if(selectedcontact.contains(cs.ocontact))
selectedcontact.remove(cs.ocontact);
}
}
}

public ApexPages.StandardSetController standardSetCon {
get {
if(standardSetCon == null) {
standardSetCon = new ApexPages.StandardSetController(Database.getQueryLocator(contactListQuery));
// sets the number of records in each page set
standardSetCon .setPageSize(20);
}
return standardSetCon ;
}
set;
}

public List<contactSet> getCurrentList() {
updateSelectedContact();
contactSetList = new List<contactSet>();
for (contact category : (List<contact>)standardSetCon.getRecords()){
if(selectedContact.contains(category))
contactSetList.add(new contactSet(category,'true'));
else
contactSetList.add(new contactSet(category));
}
fals=false;
return contactSetList;
}

public PageReference refreshList2() {
standardSetCon = null;
string s;
if(apexpages.currentpage().getparameters().get('alpha') == 'All')
s='%';
else
s= apexpages.currentpage().getparameters().get('alpha')+'%';

contactListQuery= 'select id,name,phone,Email,Email_1__c,AccountId,Status__c from contact where name like' +'\''+s +'\''+ 'limit 5000';
return null;
}



public List<contact> getDisplaySelectedList(){
updateSelectedContact();
List<contact> displaycon = new list<contact>();
displaycon.addall(selectedcontact);
return displaycon;
}

public class contactSet {
public Boolean checked{ get; set; }
public contact ocontact { get; set;}

public contactSet(){
ocontact = new contact();
checked = false;
}
public contactSet(contact c){
ocontact = c;
checked = false;

}
public contactSet(contact c,string s){
ocontact = c;
checked = true;

}
}

//public Custom_Email_Folder() {
//allEmailTemplates = [select Id, Name, Subject, Body, FolderId from EmailTemplate limit 100 ];
// allEmailTemplateFolders = [select Id, Name from Folder where Type = 'Email' ];
// }

public List<SelectOption> getEmailTemplateFolderOpts() {
allEmailTemplates = [select Id, Name, Subject, Body, FolderId from EmailTemplate ];
allEmailTemplateFolders = [select Id, Name from Folder where Type = 'Email'];
List<SelectOption> opts = new List<SelectOption>();
opts.add(new SelectOption('null', ' - Select - '));
for ( Folder f : allEmailTemplateFolders )
opts.add(new SelectOption(f.Id, f.Name));
// add an option for templates in the Unfiled Public folder
opts.add(new SelectOption(UserInfo.getOrganizationId(), 'Unified Public Email Templates'));
opts.add(new SelectOption(UserInfo.getUserId(), 'My Personal Email Templates'));
return opts;
}

public List<SelectOption> getEmailTemplateOpts() {
allEmailTemplates = [select Id, Name, Subject, Body, FolderId from EmailTemplate ];
allEmailTemplateFolders = [select Id, Name from Folder where Type = 'Email'];
List<SelectOption> opts = new List<SelectOption>();
if ( selectedEmailTemplateFolder != null ) {
opts.add(new SelectOption('null', ' - Select - '));
Id selectedId = (Id) selectedEmailTemplateFolder;
for ( EmailTemplate et : allEmailTemplates ) {
if ( et.FolderId == selectedId )
opts.add(new SelectOption(et.Id, et.Name));
}
}
return opts;
}

public PageReference refreshEmailTemplateSection() {
// this is a bit ugly, but a consequence of not being able to set a SelectOption's value to null
if ( selectedEmailTemplateFolder == null || selectedEmailTemplateFolder == 'null' ) {
selectedEmailTemplateFolder = null;
selectedEmailTemplate = null;
}
if ( selectedEmailTemplate == null || selectedEmailTemplate == 'null' ) {
selectedEmailTemplate = null;
chosenEmailTemplate = null;
} else {
Id selectedId = (Id) selectedEmailTemplate;
for ( EmailTemplate et : allEmailTemplates ) {
if ( et.Id == selectedId ) {
chosenEmailTemplate = et;
break;
}
}
}
return null;
}
public String getPrintView()
{
return
'<!--[if gte mso 9]>' +
'<xml>' +
'<w:WordDocument>' +
'<w:View>Print</w:View>' +
'<w:Zoom>100</w:Zoom>' +
'<w:DoNotOptimizeForBrowser/>' +
'</w:WordDocument>' +
'</xml>' +
'<![endif]>';
}

}

Vinita_SFDCVinita_SFDC

Hello,

 

Did you try using Standard List controller (http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_sosc_about.htm) ? If yes, then please share the error you are getting.

 

If not, then try implementing with Standard list controller. Refer following help document for details on Standard list controller:

 

http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_sosc_list_views.htm