Skip to content

Instantly share code, notes, and snippets.

@kejun91
Created March 31, 2014 15:14
Show Gist options
  • Save kejun91/9894671 to your computer and use it in GitHub Desktop.
Save kejun91/9894671 to your computer and use it in GitHub Desktop.
pagination in salesforce
<!-- 开发人: MI-->
<!-- 开发时间:2012-09-26 -->
<!-- 模块:联系人 -->
<!-- 编号:DEV00000076 -->
<!-- 2012/11/29 GAO修改:在新建联系人的时候,需要把客户的网址,电话、联系地址,邮编、传真带入到联系人中 -->
<apex:page standardcontroller="Account"
extensions="Anyue_ShowContactByType" showheader="false" sidebar="false">
<apex:form >
<apex:pageblock >
<apex:commandbutton onclick="javascript:window.open('{!instanceUrl}/003/e?retURL=%2F{!accountId}&accid={!accountId}&00N90000004IUwI={!Account.Website}&00N90000004KA4y={!Account.Anyue_DirectLine__c}&00N90000004IUw3={!Account.ExpressAddress__c}&00N90000004KA5I={!Account.Anyue_PostalCode__c}&00N90000004KA4u={!Account.AddressDetails__c}&00N90000004KA5C={!Account.Fax}','newwindow')"
value="新建联系人" />
<br></br>
<apex:pageblocksection id="result" columns="1"
title="共有联系人记录:{!categoryNumber}条">
<apex:pageblocktable value="{!list_contact}" var="c">
<apex:column headerValue="{!$ObjectType.Contact.fields.Name.label}">
<apex:outputLink value="/{!c.Id}" id="theLink" target="_blank">{!c.Name}</apex:outputLink>
</apex:column>
<apex:repeat value="{!fields}" var="f">
<apex:column value="{!c[f.fieldPath]}" />
</apex:repeat>
</apex:pageblocktable>
<apex:panelGrid columns="6">
<apex:commandLink action="{!first}" rendered="{!hasPrevious}">首页</apex:commandlink>
<apex:commandLink action="{!previous}" rendered="{!hasPrevious}">上一页</apex:commandlink>
<apex:commandLink action="{!next}" rendered="{!hasNext}">下一页</apex:commandlink>
<apex:commandLink action="{!last}" rendered="{!hasNext}">尾页</apex:commandlink>
<apex:outputText value="第{!pageNumber}页" />
<apex:outputText value="本页共{!result}条" />
</apex:panelGrid>
</apex:pageblocksection>
<apex:pageblocksection title="按联系人类型查看" columns="1"
collapsible="true">
<apex:outputpanel >
<table style="width: 900px;">
<tr align="right">
<td width="200px"><apex:outputLabel value="{!$ObjectType.Contact.fields.Anyue_TrainingContact__c.label}"
for="Anyue_TrainingContact__c" /> <apex:inputfield value="{!con.Anyue_TrainingContact__c}"
id="Anyue_TrainingContact__c" /></td>
<td width="200px"><apex:outputLabel value="{!$ObjectType.Contact.fields.Publicmember__c.label}"
for="Publicmember__c" /> <apex:inputfield value="{!con.Publicmember__c}" id="Publicmember__c" /></td>
<td width="200px"><apex:outputLabel value="{!$ObjectType.Contact.fields.Anyue_InternalTrainingContact__c.label}"
for="Anyue_InternalTrainingContact__c" /> <apex:inputfield value="{!con.Anyue_InternalTrainingContact__c}"
id="Anyue_InternalTrainingContact__c" /></td>
<td width="200px"><apex:outputLabel value="{!$ObjectType.Contact.fields.Inhousemember__c.label}"
for="Inhousemember__c" /> <apex:inputfield value="{!con.Inhousemember__c}" id="Inhousemember__c" /></td>
</tr>
<tr align="right">
<td><apex:outputLabel value="{!$ObjectType.Contact.fields.Anyue_VisitStudent__c.label}"
for="Anyue_VisitStudent__c" /> <apex:inputfield value="{!con.Anyue_VisitStudent__c}" id="Anyue_VisitStudent__c" />
</td>
<td><apex:outputLabel value="{!$ObjectType.Contact.fields.Anyue_CampaignMember__c.label}"
for="Anyue_CampaignMember__c" /> <apex:inputfield value="{!con.Anyue_CampaignMember__c}"
id="Anyue_CampaignMember__c" /></td>
<td><apex:outputLabel value="{!$ObjectType.Contact.fields.Anyuemember__c.label}"
for="Anyuemember__c" /> <apex:inputfield value="{!con.Anyuemember__c}" id="Anyuemember__c" /></td>
</tr>
</table>
</apex:outputpanel>
<apex:outputpanel >
<apex:commandbutton value="查询" action="{!queryContact}"
reRender="result" status="changeStatus" />
<apex:actionStatus id="changeStatus">
<apex:facet name="start">
<apex:image id="loading" value="{!$Resource.Loading}" />
</apex:facet>
</apex:actionStatus>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</apex:outputpanel>
</apex:pageblocksection>
</apex:pageblock>
</apex:form>
<script>
window.onload = displaySection();
function displaySection()
{
var sec = document.getElementsByName('按联系人类型查看');
twistSection(sec[0]);
}
</script>
</apex:page>
 
*
*开发人:MI
*时间:2012-09-26
*模块:联系人
*编号:DEV00000076
*功能描述:客户下自定义联系人列表根据联系人类型显示相应的结果
*注意事项:
*开发经验:
*/
public class Anyue_ShowContactByType 
{
  
  public string accountId{get;set;}
  public Contact con{get;set;}
  string query = '';
  public string instanceUrl{get;set;}
  
  public Anyue_ShowContactByType(ApexPages.StandardController c)
  {
    con = new Contact();
    accountId = c.getId();
    query = queryContact();
    instanceUrl = URL.getSalesforceBaseUrl().toExternalForm();
  }
    
    public List<Schema.FieldSetMember> getFields() 
    {
        return SObjectType.Contact.FieldSets.DisplayColumns.getFields();
    }
    
    public string queryContact()
    {
      string queryStr = 'SELECT id,Name';
      
      for(Schema.FieldSetMember f : getFields())
      {
        queryStr += ',' + f.getFieldPath();
      }
      
      queryStr += ' from Contact where AccountId = \''+accountId+'\' ';
      
      for(Schema.FieldSetMember f : SObjectType.Contact.FieldSets.Filter.getFields())
      {
        if(con.get(f.getFieldPath())==null)
        {
          continue;
        }
        if(boolean.valueOf(con.get(f.getFieldPath())))
        {
          queryStr += 'and '+f.getFieldPath() + '= true ';
        }
      }
      
      return queryStr += 'order by Initial__c ASC';
    }
    
    public ApexPages.StandardSetController conset 
    {
    get 
    {
      if(conset == null) 
      {
        conset = new ApexPages.StandardSetController(Database.getQueryLocator(query));
        conset.setPageSize(100);
      }
      return conset;
    }
    set;
  }
  
  public integer result{get;set;}
  public list<Contact> getlist_contact ()
  {
    list<Contact> list_contact = new list<Contact>();
    for(Contact c : (list<Contact>)conset.getRecords())
    {
      list_contact.add(c);
    }  
    result = list_contact.size();
    return list_contact;
  }
    
  public Boolean hasPrevious 
  {
    get 
    {
      return conset.getHasPrevious();
    }
    set;
  }
  
  public Boolean hasNext 
  {
    get 
    {
      return conset.getHasNext();
    }
    set;
    }
    // returns the page number of the current page set
  public Integer pageNumber 
  {
    get 
    {
      return conset.getPageNumber();
    }
    set;
  }
    
   // returns the first page of records
  public void first() 
  {
    conset.first();
  }
   // returns the last page of records
  public void last() 
  {
    conset.last();
  }
   // returns the previous page of records
  public void previous() 
  {
    conset.previous();
  }
   // returns the next page of records
  public void next() 
  {
    conset.next();
  }
   //returns the number of 
  public Integer categoryNumber 
  {
    get 
    {
      return conset.getResultSize();
    }
    set;
   }
    
    static testMethod void test()
    {
      Account a = new Account();
      a.Name = 'sdfdsf';
      insert a;
      Anyue_ShowContactByType ast = new Anyue_ShowContactByType(new ApexPages.StandardController(a));
      ast.getFields();
      ast.queryContact();
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment