<apex:page controller="ContactsManagerController" docType="html-5.0" tabStyle="Contact">
<!--apex:page standardController="Contact" extensions="ContactsManagerController"-->
<apex:sectionHeader title="Contact" subtitle="Contact Manager" />
<apex:form >
<apex:pageBlock rendered="true" id="showmsg" mode="maindetail">
<!-- Messages -->
<apex:outputPanel title="">
<apex:pageMessages ></apex:pageMessages>
</apex:outputPanel>
<apex:pageBlockSection title="All Contacts" collapsible="false" >
<!-- Search block-->
<apex:outputPanel >
<apex:outputLabel value="First / Last Name: " for="con" id="label"/>
<apex:inputText value="{!searchString}" title="First / Last Name" id="con"/>
<apex:commandButton action="{!Search}" title=" Search records by criteria" value=" Search " rendered="true" />
</apex:outputPanel>
<!-- New Contact button-->
<apex:outputPanel style="float:right">
<apex:commandButton action="{!newContact}" title=" New Contact " value=" New Contact " rendered="true" />
</apex:outputPanel>
</apex:pageBlockSection>
<!-- Navigation/Pagination block -->
<apex:pageBlockButtons location="bottom" title="Navigation" >
<!-- Navigation buttons -->
<apex:commandButton action="{!First}" title="First page" value="First" rendered="true" disabled="{!currentPage==1}"/>
<apex:commandButton action="{!Prev}" title="Previous page" value="Prev" rendered="true" disabled="{!currentPage==1}"/>
<!-- Page number information -->
<apex:outputPanel style="float:center;">
<apex:outputText > Page {!currentPage} of {!pageCount} </apex:outputText>
</apex:outputPanel>
<!-- Navigation buttons -->
<apex:commandButton action="{!Next}" title="Next page" value="Next" rendered="true" disabled="{!currentPage==pageCount}"/>
<apex:commandButton action="{!End}" title="Last page" value="Last" rendered="true" disabled="{!currentPage==pageCount}"/>
<!-- Page count records for pagination -->
<apex:outputPanel style="float:right;">
Items per page:
<apex:selectList value="{!pageSize}" size="1" onchange="setItemsPerPage();" title="Records per page">
<apex:selectOptions value="{!pageSizeItems}"/>
</apex:selectList>
<apex:actionFunction name="setItemsPerPage" action="{!setItemsPerPage}"/>
</apex:outputPanel>
</apex:pageBlockButtons>
<!-- Contacts list block -->
<apex:pageBlockSection title="Contacts Information" collapsible="false" columns="1">
<apex:pageBlockTable value="{!contactsList}" var="item" id="contactTable">
<!-- Columns -->
<apex:column >
<apex:facet name="header">
<!-- Change ordering -->
<apex:commandLink value="Name" action="{!setOrderIndex}" reRender="contactTable">
<apex:param name="orderIndex" value="0" assignTo="{!orderIndex}" />
</apex:commandLink>
</apex:facet>
<apex:outputLink value="/{!item.id}">
<apex:outputField value="{!item.name}" />
</apex:outputLink>
</apex:column>
<apex:column >
<apex:facet name="header">
<apex:commandLink value="Email" action="{!setOrderIndex}" reRender="contactTable">
<apex:param name="orderIndex" value="1" assignTo="{!orderIndex}" />
</apex:commandLink>
</apex:facet>
<apex:outputField value="{!item.email}" />
</apex:column>
<apex:column >
<apex:facet name="header">
<apex:commandLink value="Contact Level" action="{!setOrderIndex}" reRender="contactTable">
<apex:param name="orderIndex" value="2" assignTo="{!orderIndex}" />
</apex:commandLink>
</apex:facet>
<apex:outputField value="{!item.Contact_Level__c}" />
</apex:column>
<apex:column >
<apex:facet name="header">
<apex:commandLink value="Account" action="{!setOrderIndex}" reRender="contactTable">
<apex:param name="orderIndex" value="3" assignTo="{!orderIndex}" />
</apex:commandLink>
</apex:facet>
<apex:outputField value="{!item.Account.Name}" />
</apex:column>
<apex:column >
<apex:facet name="header">
<apex:commandLink value="Owner" action="{!setOrderIndex}" reRender="contactTable">
<apex:param name="orderIndex" value="4" assignTo="{!orderIndex}" />
</apex:commandLink>
</apex:facet>
<apex:outputField value="{!item.Owner.name}" />
</apex:column>
<apex:column >
<apex:facet name="header">
<apex:commandLink value="Created By" action="{!setOrderIndex}" reRender="contactTable">
<apex:param name="orderIndex" value="5" assignTo="{!orderIndex}" />
</apex:commandLink>
</apex:facet>
<apex:outputField value="{!item.CreatedBy.Name}" />
</apex:column>
<apex:column >
<apex:facet name="header">
<apex:commandLink value="Created date" action="{!setOrderIndex}" reRender="contactTable">
<apex:param name="orderIndex" value="6" assignTo="{!orderIndex}" />
</apex:commandLink>
</apex:facet>
<apex:outputField value="{!item.CreatedDate}" />
</apex:column>
<apex:column >
<!-- Delete current record button -->
<apex:commandButton action="{!del}" title=" Delete current record " value=" Del " reRender="showmsg" rendered="true"
onclick="if(!confirm('You are trying to delete the entry. Are you sure?')){return false};">
<apex:param name="contactId" assignTo="{!contactId}" value="{!item.Id}"/>
</apex:commandButton>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
а вот class
public with sharing class ContactsManagerController {
// New Contact page
private final String NEW_CONTACT_PAGE = '/apex/NewContact';
//list of Contacts
public List<Contact> contactsList {get; private set;}
//list of fields to be getted from database (for ordering logic)
private List<String> contactsFieldList {get; private set;}
// total count records
private integer contactsListCount {get;set;}
// offset for pagination
private integer contactsListOffset {get;set;}
// ordering
public integer orderIndex {get;set;}
// order direction
private String orderDirection {get;set;}
private integer prevOrderIndex = 0;
// pagination
public final integer PAGE_SIZE_DEFAULT_INDEX = 1;
public List<SelectOption> pageSizeItems {get; private set;}
public integer pageSize {get;set;}
public integer pageCount {get;set;}
public integer currentPage {get;set;}
// for deleting and searching commands
public String contactId {get;set;}
public String searchString {get;set;}
//constructor without standatd controller
public ContactsManagerController(){
// create fields list
this.contactsFieldList = new List<String>{'Name',
'Email',
'Contact_Level__c',
'Account.Name',
'Owner.Name',
'CreatedBy.Name',
'CreatedDate'};
//create count items per page allowable values list
this.pageSizeItems = new List<SelectOption>{
new SelectOption('5','5'),
new SelectOption('10','10'),
new SelectOption('20','20'),
new SelectOption('50','50'),
new SelectOption('100','100')};
// set default count items per page
this.pageSize = Integer.valueOf(pageSizeItems.get(PAGE_SIZE_DEFAULT_INDEX).getValue());
//set default filter to search
this.searchString = '';
//set default column number to ordering
this.orderIndex = 0;
//set default direction to ordering
this.orderDirection = 'ASC';
// set default offset for pagination
this.contactsListOffset = 0;
//build contacts list
getContactsList();
}
// make new list of contactsList using pagination and ordering
private void getContactsList(){
//refrech total records
getTotalRecords();
// notnalize value to '' if null
this.searchString = (searchString==null) ? '' : searchString;
// calculate current page
this.currentPage=contactsListOffset+1;
// fetch records from database
this.contactsList = Database.query('SELECT '+
String.join(contactsFieldList, ',')+
' FROM contact '+
' WHERE firstName like \'%'+searchString+'%\' OR lastName like \'%'+searchString+'%\' '+
' ORDER BY '+contactsFieldList.get(orderIndex)+' '+orderDirection+
' LIMIT '+pageSize+
' OFFSET '+contactsListOffset*pageSize);
}
// get total count of records
private void getTotalRecords(){
// notnalize value to '' if null
this.searchString = (searchString==null) ? '' : searchString;
// fetch total count from database
this.contactsListCount = Database.countQuery('select count() FROM contact '+' WHERE firstName like \'%'+searchString+'%\' OR lastName like \'%'+searchString+'%\' ');
// calculate page count
this.pageCount = ((contactsListCount / pageSize)*pageSize!=contactsListCount)
? (contactsListCount / pageSize+1) : (contactsListCount / pageSize);
// show message if no recirds found
if(contactsListCount==0 && ApexPages.currentPage()!=null){
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.WARNING,'No records found'));
}
}
// get records for first page
public void first(){
this.contactsListOffset = 0;
//rebuild contacts list
getContactsList();
}
// get records for previous pages
public void prev(){
this.contactsListOffset = (contactsListOffset>0) ? contactsListOffset-1 : contactsListOffset;
//rebuild contacts list
getContactsList();
}
//get records for next page
public void next(){
this.contactsListOffset = ((contactsListOffset+1)*pageSize<contactsListCount)
? contactsListOffset+1 : contactsListOffset;
//rebuild contacts list
getContactsList();
}
//get records for last pages
public void end(){
contactsListOffset = contactsListCount / pageSize;
this.contactsListOffset = (contactsListOffset*pageSize==contactsListCount && contactsListOffset>0)
? contactsListOffset-1 : contactsListOffset;
//rebuild contacts list
getContactsList();
}
// set order and order direction
public void setOrderIndex(){
if(prevOrderIndex==orderIndex){
if('ASC'.equals(orderDirection))
this.orderDirection = 'DESC';
else
this.orderDirection = 'ASC';
} else {
this.prevOrderIndex=orderIndex;
this.orderDirection = 'ASC';
}
//rebuild contacts list
getContactsList();
}
// delele decord
public void del(){
if(contactId==null)
return;
// get contact by Id
Contact cnt = [select Id from contact where Id = :contactId];
// delete contact
delete cnt;
if(ApexPages.currentPage()!=null){
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO,'Contact #'+contactId+' was deleted'));
}
//rebuild contacts list
getContactsList();
}
// search and show records
public void search(){
this.contactsListOffset = 0;
//rebuild contacts list
getContactsList();
}
// re init count items per page
public void setItemsPerPage(){
//rebuild contacts list
getContactsList();
}
// redirect to new contact page
public PageReference newContact(){
PageReference pr = new PageReference(NEW_CONTACT_PAGE);
pr.setRedirect(true);
return pr;
}
}
<apex:page controller="ContactsManagerController" docType="html-5.0" tabStyle="Contact"> <!--apex:page standardController="Contact" extensions="ContactsManagerController"--> <apex:sectionHeader title="Contact" subtitle="Contact Manager" /> <apex:form > <apex:pageBlock rendered="true" id="showmsg" mode="maindetail"> <!-- Messages --> <apex:outputPanel title=""> <apex:pageMessages ></apex:pageMessages> </apex:outputPanel> <apex:pageBlockSection title="All Contacts" collapsible="false" > <!-- Search block--> <apex:outputPanel > <apex:outputLabel value="First / Last Name: " for="con" id="label"/> <apex:inputText value="{!searchString}" title="First / Last Name" id="con"/> <apex:commandButton action="{!Search}" title=" Search records by criteria" value=" Search " rendered="true" /> </apex:outputPanel> <!-- New Contact button--> <apex:outputPanel style="float:right"> <apex:commandButton action="{!newContact}" title=" New Contact " value=" New Contact " rendered="true" /> </apex:outputPanel> </apex:pageBlockSection> <!-- Navigation/Pagination block --> <apex:pageBlockButtons location="bottom" title="Navigation" > <!-- Navigation buttons --> <apex:commandButton action="{!First}" title="First page" value="First" rendered="true" disabled="{!currentPage==1}"/> <apex:commandButton action="{!Prev}" title="Previous page" value="Prev" rendered="true" disabled="{!currentPage==1}"/> <!-- Page number information --> <apex:outputPanel style="float:center;"> <apex:outputText > Page {!currentPage} of {!pageCount} </apex:outputText> </apex:outputPanel> <!-- Navigation buttons --> <apex:commandButton action="{!Next}" title="Next page" value="Next" rendered="true" disabled="{!currentPage==pageCount}"/> <apex:commandButton action="{!End}" title="Last page" value="Last" rendered="true" disabled="{!currentPage==pageCount}"/> <!-- Page count records for pagination --> <apex:outputPanel style="float:right;"> Items per page: <apex:selectList value="{!pageSize}" size="1" onchange="setItemsPerPage();" title="Records per page"> <apex:selectOptions value="{!pageSizeItems}"/> </apex:selectList> <apex:actionFunction name="setItemsPerPage" action="{!setItemsPerPage}"/> </apex:outputPanel> </apex:pageBlockButtons> <!-- Contacts list block --> <apex:pageBlockSection title="Contacts Information" collapsible="false" columns="1"> <apex:pageBlockTable value="{!contactsList}" var="item" id="contactTable"> <!-- Columns --> <apex:column > <apex:facet name="header"> <!-- Change ordering --> <apex:commandLink value="Name" action="{!setOrderIndex}" reRender="contactTable"> <apex:param name="orderIndex" value="0" assignTo="{!orderIndex}" /> </apex:commandLink> </apex:facet> <apex:outputLink value="/{!item.id}"> <apex:outputField value="{!item.name}" /> </apex:outputLink> </apex:column> <apex:column > <apex:facet name="header"> <apex:commandLink value="Email" action="{!setOrderIndex}" reRender="contactTable"> <apex:param name="orderIndex" value="1" assignTo="{!orderIndex}" /> </apex:commandLink> </apex:facet> <apex:outputField value="{!item.email}" /> </apex:column> <apex:column > <apex:facet name="header"> <apex:commandLink value="Contact Level" action="{!setOrderIndex}" reRender="contactTable"> <apex:param name="orderIndex" value="2" assignTo="{!orderIndex}" /> </apex:commandLink> </apex:facet> <apex:outputField value="{!item.Contact_Level__c}" /> </apex:column> <apex:column > <apex:facet name="header"> <apex:commandLink value="Account" action="{!setOrderIndex}" reRender="contactTable"> <apex:param name="orderIndex" value="3" assignTo="{!orderIndex}" /> </apex:commandLink> </apex:facet> <apex:outputField value="{!item.Account.Name}" /> </apex:column> <apex:column > <apex:facet name="header"> <apex:commandLink value="Owner" action="{!setOrderIndex}" reRender="contactTable"> <apex:param name="orderIndex" value="4" assignTo="{!orderIndex}" /> </apex:commandLink> </apex:facet> <apex:outputField value="{!item.Owner.name}" /> </apex:column> <apex:column > <apex:facet name="header"> <apex:commandLink value="Created By" action="{!setOrderIndex}" reRender="contactTable"> <apex:param name="orderIndex" value="5" assignTo="{!orderIndex}" /> </apex:commandLink> </apex:facet> <apex:outputField value="{!item.CreatedBy.Name}" /> </apex:column> <apex:column > <apex:facet name="header"> <apex:commandLink value="Created date" action="{!setOrderIndex}" reRender="contactTable"> <apex:param name="orderIndex" value="6" assignTo="{!orderIndex}" /> </apex:commandLink> </apex:facet> <apex:outputField value="{!item.CreatedDate}" /> </apex:column> <apex:column > <!-- Delete current record button --> <apex:commandButton action="{!del}" title=" Delete current record " value=" Del " reRender="showmsg" rendered="true" onclick="if(!confirm('You are trying to delete the entry. Are you sure?')){return false};"> <apex:param name="contactId" assignTo="{!contactId}" value="{!item.Id}"/> </apex:commandButton> </apex:column> </apex:pageBlockTable> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page> а вот class public with sharing class ContactsManagerController { // New Contact page private final String NEW_CONTACT_PAGE = '/apex/NewContact'; //list of Contacts public List<Contact> contactsList {get; private set;} //list of fields to be getted from database (for ordering logic) private List<String> contactsFieldList {get; private set;} // total count records private integer contactsListCount {get;set;} // offset for pagination private integer contactsListOffset {get;set;} // ordering public integer orderIndex {get;set;} // order direction private String orderDirection {get;set;} private integer prevOrderIndex = 0; // pagination public final integer PAGE_SIZE_DEFAULT_INDEX = 1; public List<SelectOption> pageSizeItems {get; private set;} public integer pageSize {get;set;} public integer pageCount {get;set;} public integer currentPage {get;set;} // for deleting and searching commands public String contactId {get;set;} public String searchString {get;set;} //constructor without standatd controller public ContactsManagerController(){ // create fields list this.contactsFieldList = new List<String>{'Name', 'Email', 'Contact_Level__c', 'Account.Name', 'Owner.Name', 'CreatedBy.Name', 'CreatedDate'}; //create count items per page allowable values list this.pageSizeItems = new List<SelectOption>{ new SelectOption('5','5'), new SelectOption('10','10'), new SelectOption('20','20'), new SelectOption('50','50'), new SelectOption('100','100')}; // set default count items per page this.pageSize = Integer.valueOf(pageSizeItems.get(PAGE_SIZE_DEFAULT_INDEX).getValue()); //set default filter to search this.searchString = ''; //set default column number to ordering this.orderIndex = 0; //set default direction to ordering this.orderDirection = 'ASC'; // set default offset for pagination this.contactsListOffset = 0; //build contacts list getContactsList(); } // make new list of contactsList using pagination and ordering private void getContactsList(){ //refrech total records getTotalRecords(); // notnalize value to '' if null this.searchString = (searchString==null) ? '' : searchString; // calculate current page this.currentPage=contactsListOffset+1; // fetch records from database this.contactsList = Database.query('SELECT '+ String.join(contactsFieldList, ',')+ ' FROM contact '+ ' WHERE firstName like \'%'+searchString+'%\' OR lastName like \'%'+searchString+'%\' '+ ' ORDER BY '+contactsFieldList.get(orderIndex)+' '+orderDirection+ ' LIMIT '+pageSize+ ' OFFSET '+contactsListOffset*pageSize); } // get total count of records private void getTotalRecords(){ // notnalize value to '' if null this.searchString = (searchString==null) ? '' : searchString; // fetch total count from database this.contactsListCount = Database.countQuery('select count() FROM contact '+' WHERE firstName like \'%'+searchString+'%\' OR lastName like \'%'+searchString+'%\' '); // calculate page count this.pageCount = ((contactsListCount / pageSize)*pageSize!=contactsListCount) ? (contactsListCount / pageSize+1) : (contactsListCount / pageSize); // show message if no recirds found if(contactsListCount==0 && ApexPages.currentPage()!=null){ ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.WARNING,'No records found')); } } // get records for first page public void first(){ this.contactsListOffset = 0; //rebuild contacts list getContactsList(); } // get records for previous pages public void prev(){ this.contactsListOffset = (contactsListOffset>0) ? contactsListOffset-1 : contactsListOffset; //rebuild contacts list getContactsList(); } //get records for next page public void next(){ this.contactsListOffset = ((contactsListOffset+1)*pageSize<contactsListCount) ? contactsListOffset+1 : contactsListOffset; //rebuild contacts list getContactsList(); } //get records for last pages public void end(){ contactsListOffset = contactsListCount / pageSize; this.contactsListOffset = (contactsListOffset*pageSize==contactsListCount && contactsListOffset>0) ? contactsListOffset-1 : contactsListOffset; //rebuild contacts list getContactsList(); } // set order and order direction public void setOrderIndex(){ if(prevOrderIndex==orderIndex){ if('ASC'.equals(orderDirection)) this.orderDirection = 'DESC'; else this.orderDirection = 'ASC'; } else { this.prevOrderIndex=orderIndex; this.orderDirection = 'ASC'; } //rebuild contacts list getContactsList(); } // delele decord public void del(){ if(contactId==null) return; // get contact by Id Contact cnt = [select Id from contact where Id = :contactId]; // delete contact delete cnt; if(ApexPages.currentPage()!=null){ ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO,'Contact #'+contactId+' was deleted')); } //rebuild contacts list getContactsList(); } // search and show records public void search(){ this.contactsListOffset = 0; //rebuild contacts list getContactsList(); } // re init count items per page public void setItemsPerPage(){ //rebuild contacts list getContactsList(); } // redirect to new contact page public PageReference newContact(){ PageReference pr = new PageReference(NEW_CONTACT_PAGE); pr.setRedirect(true); return pr; } }
Читал я название темы, читал, да так и не понял что куда и где.
Вроде и комментарии в коде на английском, и код пишется на английском, а вопрос на русском, что там спрашивается?
Вы уж если кодите что-то в английской системе, то используйте английский язык для интерфейса
Читал я название темы, читал, да так и не понял что куда и где. Вроде и комментарии в коде на английском, и код пишется на английском, а вопрос на русском, что там спрашивается? Вы уж если кодите что-то в английской системе, то используйте английский язык для интерфейса
Error: Could not resolve field 'Contact_Level__c' from <apex:outputField> value binding '{!item.Contact_Level__c}' in page ContactManager
Error: Could not resolve field 'Contact_Level__c' from <apex:outputField> value binding '{!item.Contact_Level__c}' in page ContactManager
//list of Contacts
public List<Contact> contactsList {get; private set;}
//list of fields to be getted from database (for ordering logic)
private List<String> contactsFieldList {get; private set;}
// total count records
private integer contactsListCount {get;set;}
// offset for pagination
private integer contactsListOffset {get;set;}
// ordering
public integer orderIndex {get;set;}
// order direction
private String orderDirection {get;set;}
private integer prevOrderIndex = 0;
// pagination
public final integer PAGE_SIZE_DEFAULT_INDEX = 1;
public List<SelectOption> pageSizeItems {get; private set;}
public integer pageSize {get;set;}
public integer pageCount {get;set;}
public integer currentPage {get;set;}
// for deleting and searching commands
public String contactId {get;set;}
public String searchString {get;set;}
//constructor without standatd controller
public ContactsManagerController(){
// create fields list
this.contactsFieldList = new List<String>{'Name',
'Email',
'Contact_Level__c',
'Account.Name',
'Owner.Name',
'CreatedBy.Name',
'CreatedDate'};
//create count items per page allowable values list
this.pageSizeItems = new List<SelectOption>{
new SelectOption('5','5'),
new SelectOption('10','10'),
new SelectOption('20','20'),
new SelectOption('50','50'),
new SelectOption('100','100')};
// set default count items per page
this.pageSize = Integer.valueOf(pageSizeItems.get(PAGE_SIZE_DEFAULT_INDEX).getValue());
//set default filter to search
this.searchString = '';
//set default column number to ordering
this.orderIndex = 0;
//set default direction to ordering
this.orderDirection = 'ASC';
// set default offset for pagination
this.contactsListOffset = 0;
//build contacts list
getContactsList();
}
// make new list of contactsList using pagination and ordering
private void getContactsList(){
//refrech total records
getTotalRecords();
// notnalize value to '' if null
this.searchString = (searchString==null) ? '' : searchString;
// calculate current page
this.currentPage=contactsListOffset+1;
// fetch records from database
this.contactsList = Database.query('SELECT '+
String.join(contactsFieldList, ',')+
' FROM contact '+
' WHERE firstName like \'%'+searchString+'%\' OR lastName like \'%'+searchString+'%\' '+
' ORDER BY '+contactsFieldList.get(orderIndex)+' '+orderDirection+
' LIMIT '+pageSize+
' OFFSET '+contactsListOffset*pageSize);
}
// get total count of records
private void getTotalRecords(){
// notnalize value to '' if null
this.searchString = (searchString==null) ? '' : searchString;
// fetch total count from database
this.contactsListCount = Database.countQuery('select count() FROM contact '+' WHERE firstName like \'%'+searchString+'%\' OR lastName like \'%'+searchString+'%\' ');
// calculate page count
this.pageCount = ((contactsListCount / pageSize)*pageSize!=contactsListCount)
? (contactsListCount / pageSize+1) : (contactsListCount / pageSize);
// show message if no recirds found
if(contactsListCount==0 && ApexPages.currentPage()!=null){
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.WARNING,'No records found'));
}
}
// get records for first page
public void first(){
this.contactsListOffset = 0;
//rebuild contacts list
getContactsList();
}
// get records for previous pages
public void prev(){
this.contactsListOffset = (contactsListOffset>0) ? contactsListOffset-1 : contactsListOffset;
//rebuild contacts list
getContactsList();
}
//get records for next page
public void next(){
this.contactsListOffset = ((contactsListOffset+1)*pageSize<contactsListCount)
? contactsListOffset+1 : contactsListOffset;
//rebuild contacts list
getContactsList();
}
//get records for last pages
public void end(){
contactsListOffset = contactsListCount / pageSize;
this.contactsListOffset = (contactsListOffset*pageSize==contactsListCount && contactsListOffset>0)
? contactsListOffset-1 : contactsListOffset;
//rebuild contacts list
getContactsList();
}
// set order and order direction
public void setOrderIndex(){
if(prevOrderIndex==orderIndex){
if('ASC'.equals(orderDirection))
this.orderDirection = 'DESC';
else
this.orderDirection = 'ASC';
} else {
this.prevOrderIndex=orderIndex;
this.orderDirection = 'ASC';
}
//rebuild contacts list
getContactsList();
}
// delele decord
public void del(){
if(contactId==null)
return;
// get contact by Id
Contact cnt = [select Id from contact where Id = :contactId];
// delete contact
delete cnt;
if(ApexPages.currentPage()!=null){
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO,'Contact #'+contactId+' was deleted'));
}
//rebuild contacts list
getContactsList();
}
// search and show records
public void search(){
this.contactsListOffset = 0;
//rebuild contacts list
getContactsList();
}
// re init count items per page
public void setItemsPerPage(){
//rebuild contacts list
getContactsList();
}
// redirect to new contact page
public PageReference newContact(){
PageReference pr = new PageReference(NEW_CONTACT_PAGE);
pr.setRedirect(true);
return pr;
}
}
Проверьте существует ли поле Contact_Level__c
Если существует - проверить правильное или нет имя у поля
[quote="lo"]public with sharing class ContactsManagerController { // New Contact page private final String NEW_CONTACT_PAGE = '/apex/NewContact'; //list of Contacts public List<Contact> contactsList {get; private set;} //list of fields to be getted from database (for ordering logic) private List<String> contactsFieldList {get; private set;} // total count records private integer contactsListCount {get;set;} // offset for pagination private integer contactsListOffset {get;set;} // ordering public integer orderIndex {get;set;} // order direction private String orderDirection {get;set;} private integer prevOrderIndex = 0; // pagination public final integer PAGE_SIZE_DEFAULT_INDEX = 1; public List<SelectOption> pageSizeItems {get; private set;} public integer pageSize {get;set;} public integer pageCount {get;set;} public integer currentPage {get;set;} // for deleting and searching commands public String contactId {get;set;} public String searchString {get;set;} //constructor without standatd controller public ContactsManagerController(){ // create fields list this.contactsFieldList = new List<String>{'Name', 'Email', 'Contact_Level__c', 'Account.Name', 'Owner.Name', 'CreatedBy.Name', 'CreatedDate'}; //create count items per page allowable values list this.pageSizeItems = new List<SelectOption>{ new SelectOption('5','5'), new SelectOption('10','10'), new SelectOption('20','20'), new SelectOption('50','50'), new SelectOption('100','100')}; // set default count items per page this.pageSize = Integer.valueOf(pageSizeItems.get(PAGE_SIZE_DEFAULT_INDEX).getValue()); //set default filter to search this.searchString = ''; //set default column number to ordering this.orderIndex = 0; //set default direction to ordering this.orderDirection = 'ASC'; // set default offset for pagination this.contactsListOffset = 0; //build contacts list getContactsList(); } // make new list of contactsList using pagination and ordering private void getContactsList(){ //refrech total records getTotalRecords(); // notnalize value to '' if null this.searchString = (searchString==null) ? '' : searchString; // calculate current page this.currentPage=contactsListOffset+1; // fetch records from database this.contactsList = Database.query('SELECT '+ String.join(contactsFieldList, ',')+ ' FROM contact '+ ' WHERE firstName like \'%'+searchString+'%\' OR lastName like \'%'+searchString+'%\' '+ ' ORDER BY '+contactsFieldList.get(orderIndex)+' '+orderDirection+ ' LIMIT '+pageSize+ ' OFFSET '+contactsListOffset*pageSize); } // get total count of records private void getTotalRecords(){ // notnalize value to '' if null this.searchString = (searchString==null) ? '' : searchString; // fetch total count from database this.contactsListCount = Database.countQuery('select count() FROM contact '+' WHERE firstName like \'%'+searchString+'%\' OR lastName like \'%'+searchString+'%\' '); // calculate page count this.pageCount = ((contactsListCount / pageSize)*pageSize!=contactsListCount) ? (contactsListCount / pageSize+1) : (contactsListCount / pageSize); // show message if no recirds found if(contactsListCount==0 && ApexPages.currentPage()!=null){ ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.WARNING,'No records found')); } } // get records for first page public void first(){ this.contactsListOffset = 0; //rebuild contacts list getContactsList(); } // get records for previous pages public void prev(){ this.contactsListOffset = (contactsListOffset>0) ? contactsListOffset-1 : contactsListOffset; //rebuild contacts list getContactsList(); } //get records for next page public void next(){ this.contactsListOffset = ((contactsListOffset+1)*pageSize<contactsListCount) ? contactsListOffset+1 : contactsListOffset; //rebuild contacts list getContactsList(); } //get records for last pages public void end(){ contactsListOffset = contactsListCount / pageSize; this.contactsListOffset = (contactsListOffset*pageSize==contactsListCount && contactsListOffset>0) ? contactsListOffset-1 : contactsListOffset; //rebuild contacts list getContactsList(); } // set order and order direction public void setOrderIndex(){ if(prevOrderIndex==orderIndex){ if('ASC'.equals(orderDirection)) this.orderDirection = 'DESC'; else this.orderDirection = 'ASC'; } else { this.prevOrderIndex=orderIndex; this.orderDirection = 'ASC'; } //rebuild contacts list getContactsList(); } // delele decord public void del(){ if(contactId==null) return; // get contact by Id Contact cnt = [select Id from contact where Id = :contactId]; // delete contact delete cnt; if(ApexPages.currentPage()!=null){ ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO,'Contact #'+contactId+' was deleted')); } //rebuild contacts list getContactsList(); } // search and show records public void search(){ this.contactsListOffset = 0; //rebuild contacts list getContactsList(); } // re init count items per page public void setItemsPerPage(){ //rebuild contacts list getContactsList(); } // redirect to new contact page public PageReference newContact(){ PageReference pr = new PageReference(NEW_CONTACT_PAGE); pr.setRedirect(true); return pr; } }[/quote] Проверьте существует ли поле Contact_Level__c Если существует - проверить правильное или нет имя у поля
Для того чтобы убедиться что поле на месте и оно правильно названо
сделай простой SOQL и запусти в developer console.
SELECT Id, Contact_Level__c FROM Contact
И с следующий раз оборачивай весь код в тег code (последняя иконка в меню)
Для того чтобы убедиться что поле на месте и оно правильно названо сделай простой SOQL и запусти в developer console. [code] SELECT Id, Contact_Level__c FROM Contact [/code] И с следующий раз оборачивай весь код в тег code (последняя иконка в меню)