You need to sign in to do that
Don't have an account?
Simha Yadav
please request anybody to add pagination code for below code....
VF Code:
<apex:page standardController="Account" extensions="WrapperDemoClass" showHeader="false" sidebar="false">
<script type="text/javascript">
function selectAllCheckboxes(obj,receivedInputID){
var inputCheckBox = document.getElementsByTagName("input");
for(var i=0; i<inputCheckBox.length; i++){
if(inputCheckBox[i].id.indexOf(receivedInputID)!=-1){
inputCheckBox[i].checked = obj.checked;
}
}
}
</script>
<apex:form >
<apex:pageBlock title=" Account Invoice" id="pgBlckId">
<br/>
<br/>
<apex:commandButton value="Send Email" action="{!sendEmail}" reRender="pgBlckId" status="actStatusId" />
<apex:actionStatus id="actStatusId" >
<apex:facet name="start" >
<apex:image url="{!$Resource.Image}"/>
</apex:facet>
</apex:actionStatus>
<br/>
<br/>
<apex:pageMessages />
<br/>
<apex:pageblockTable value="{!wrapperObj}" var="Rec" id="table" title="All Accounts">
<apex:column >
<apex:facet name="header">
<apex:inputCheckbox onclick="selectAllCheckboxes(this,'inputId')"/>
</apex:facet>
<apex:inputCheckbox value="{!Rec.checkBox}" id="inputId"/>
</apex:column>
<apex:column value="{!Rec.accObj.name}"/>
<apex:column value="{!Rec.accObj.phone}"/>
<apex:column value="{!Rec.accObj.Email__c}"/>
<apex:column value="{!Rec.accObj.createddate}"/>
<apex:column value="{!Rec.accObj.Email_Status__c}"/>
</apex:pageblockTable>
</apex:pageblock>
</apex:form>
</apex:page>
Apex Class:
public with sharing class WrapperDemoClass {
Public List<WrapperClassEx> WrapperList{get;set;}
public List<Account> accList {get;set;}
public boolean checked {get;set;}
public WrapperDemoClass(ApexPages.StandardController controller) {
}
Public List<WrapperClassEx> getwrapperObj(){
accList = [Select id,name,phone,type,industry,Email__c,createddate,Email_Status__c from account limit 15];
WrapperList = New List<WrapperClassEx>();
for(Account acc: accList){
WrapperList.add(New WrapperClassEx(acc,false));
}
system.debug('WrapperList :'+WrapperList);
return WrapperList;
}
public void sendEmail(){
List<Messaging.SingleEmailMessage> lstEmailId=new List<Messaging.SingleEmailMessage>();
PageReference pdf = Page.newreq;
// add parent id to the parameters for standardcontroller
//pdf.getParameters().put('id',accountId);
// the contents of the attachment from the pdf
Blob body;
try {
// returns the output of the page as a PDF
body = pdf.getContent();
// need to pass unit test -- current bug
} catch (VisualforceException e) {
body = Blob.valueOf('Some Text');
}
for(WrapperClassEx w: WrapperList){
system.debug('w.checkBox :'+w.checkBox);
if(w.checkBox == true){
Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
attach.setContentType('application/pdf');
attach.setFileName('Invoice.pdf');
attach.setInline(false);
attach.Body = body;
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(new String[] {w.accObj.Email__c});
//mail.setReplyTo('sumit.shukla@magicsw.com');
mail.setplainTextBody('Hello');
mail.setSenderDisplayName('Your Company Name');
mail.setSubject('Test Email From Force.com Sites');
mail.setFileAttachments(new Messaging.EmailFileAttachment[] { attach });
lstEmailId.add(mail);
system.debug('lstEmailId :'+lstEmailId);
}
}
if(lstEmailId.size()>0){
try{
Messaging.sendEmail(lstEmailId);
checked = true;
ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.Confirm,'Sent!'));
}Catch(Exception ee){
ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.Error,ee.getMessage()));
}
}
}
Public Class WrapperClassEx{
Public Account accObj{get;set;}
Public Boolean checkBox{get;set;}
Public WrapperClassEx(Account accRec, boolean SelectBox){
accObj = accRec;
checkBox = SelectBox;
}
}
}
<apex:page standardController="Account" extensions="WrapperDemoClass" showHeader="false" sidebar="false">
<script type="text/javascript">
function selectAllCheckboxes(obj,receivedInputID){
var inputCheckBox = document.getElementsByTagName("input");
for(var i=0; i<inputCheckBox.length; i++){
if(inputCheckBox[i].id.indexOf(receivedInputID)!=-1){
inputCheckBox[i].checked = obj.checked;
}
}
}
</script>
<apex:form >
<apex:pageBlock title=" Account Invoice" id="pgBlckId">
<br/>
<br/>
<apex:commandButton value="Send Email" action="{!sendEmail}" reRender="pgBlckId" status="actStatusId" />
<apex:actionStatus id="actStatusId" >
<apex:facet name="start" >
<apex:image url="{!$Resource.Image}"/>
</apex:facet>
</apex:actionStatus>
<br/>
<br/>
<apex:pageMessages />
<br/>
<apex:pageblockTable value="{!wrapperObj}" var="Rec" id="table" title="All Accounts">
<apex:column >
<apex:facet name="header">
<apex:inputCheckbox onclick="selectAllCheckboxes(this,'inputId')"/>
</apex:facet>
<apex:inputCheckbox value="{!Rec.checkBox}" id="inputId"/>
</apex:column>
<apex:column value="{!Rec.accObj.name}"/>
<apex:column value="{!Rec.accObj.phone}"/>
<apex:column value="{!Rec.accObj.Email__c}"/>
<apex:column value="{!Rec.accObj.createddate}"/>
<apex:column value="{!Rec.accObj.Email_Status__c}"/>
</apex:pageblockTable>
</apex:pageblock>
</apex:form>
</apex:page>
Apex Class:
public with sharing class WrapperDemoClass {
Public List<WrapperClassEx> WrapperList{get;set;}
public List<Account> accList {get;set;}
public boolean checked {get;set;}
public WrapperDemoClass(ApexPages.StandardController controller) {
}
Public List<WrapperClassEx> getwrapperObj(){
accList = [Select id,name,phone,type,industry,Email__c,createddate,Email_Status__c from account limit 15];
WrapperList = New List<WrapperClassEx>();
for(Account acc: accList){
WrapperList.add(New WrapperClassEx(acc,false));
}
system.debug('WrapperList :'+WrapperList);
return WrapperList;
}
public void sendEmail(){
List<Messaging.SingleEmailMessage> lstEmailId=new List<Messaging.SingleEmailMessage>();
PageReference pdf = Page.newreq;
// add parent id to the parameters for standardcontroller
//pdf.getParameters().put('id',accountId);
// the contents of the attachment from the pdf
Blob body;
try {
// returns the output of the page as a PDF
body = pdf.getContent();
// need to pass unit test -- current bug
} catch (VisualforceException e) {
body = Blob.valueOf('Some Text');
}
for(WrapperClassEx w: WrapperList){
system.debug('w.checkBox :'+w.checkBox);
if(w.checkBox == true){
Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
attach.setContentType('application/pdf');
attach.setFileName('Invoice.pdf');
attach.setInline(false);
attach.Body = body;
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setToAddresses(new String[] {w.accObj.Email__c});
//mail.setReplyTo('sumit.shukla@magicsw.com');
mail.setplainTextBody('Hello');
mail.setSenderDisplayName('Your Company Name');
mail.setSubject('Test Email From Force.com Sites');
mail.setFileAttachments(new Messaging.EmailFileAttachment[] { attach });
lstEmailId.add(mail);
system.debug('lstEmailId :'+lstEmailId);
}
}
if(lstEmailId.size()>0){
try{
Messaging.sendEmail(lstEmailId);
checked = true;
ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.Confirm,'Sent!'));
}Catch(Exception ee){
ApexPages.AddMessage(new ApexPages.Message(ApexPages.Severity.Error,ee.getMessage()));
}
}
}
Public Class WrapperClassEx{
Public Account accObj{get;set;}
Public Boolean checkBox{get;set;}
Public WrapperClassEx(Account accRec, boolean SelectBox){
accObj = accRec;
checkBox = SelectBox;
}
}
}
Please find help on the below mentioned links :
- https://developer.salesforce.com/docs/atlas.en-us.knowledge_dev.meta/knowledge_dev/knowledge_customize_searchpage_visualforce_02pagination.htm
- https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_sosc_pagination.htm
Just go through these links and you will find methods of pagination which you can copy and paste into your page and class.Let me know if you need more help on this
Thanks,
Abhishek