You need to sign in to do that
Don't have an account?
Not able to stored previous page selected rows in wrapper class.
Hi,
Below controller is a wrapper class using pagination. Issue I am facing here is I am displaying pages in pagination User can select rows and insert the data.
Problem here is previous selected rows once moved to next page is not getting stored.
Only the currect page which is selected are getting stored not the previous page. Please suggest me how to fix.
Controller
public with sharing class CCW_ContactPaginationController {
//URL Passing Parameters.
String PageContractId = ApexPages.currentPage().getParameters().get('ContractId');
String PageAccountId = ApexPages.currentPage().getParameters().get('AccountId');
public Asset GetAccount{get;set;}
public Asset GetContract{get;set;}
public Asset GetExpireDate{get;set;}
public Asset GetReseller{get;set;}
public Asset GetDistributor{get;set;}
public Boolean IncumbentReseller{get;set;}
public Boolean Education{get;set;}
public Asset GetOpportunity{get;set;}
public Asset GetNewOpportunity{get;set;}
public String ExpireTerms{get;set;}
//Our collection to class/wrapper objects wrapAsset
public List<CCWRowItem> wrapAssetList {get; set;}
public List<Asset> selectedAssets{get;set;}
/*
* item in context from the page
*/
public String contextItem{get;set;}
/*
* set controller
*/
private ApexPages.StandardSetController setCon;
/*
* the contact ids selected by the user
*/
private Set<Id> selectedContactIds;
/*
* constructor
*/
public CCW_ContactPaginationController ()
{
GetAccount = new Asset(); //Get Account Id from Page
GetContract = new Asset(); //Get Contract Name from Page
GetExpireDate = new Asset(); // Date Picker
GetReseller = new Asset();
GetDistributor = new Asset();
GetOpportunity = new Asset(); // Get Opportunity Id
GetNewOpportunity = new Asset(); // Get New Opportunity Name
fetch_data();
}
// public List<Asset> Asset_yourObjList{get;set;}
public void fetch_data ()
{
//init variable
this.selectedContactIds= new Set<Id>();
//gather data set
If ( GetAccount.AccountId == NULL || GetContract.Name == NULL )
{
If ( PageContractId <> NULL )
{
Contract C;
C = [SELECT Name FROM Contract WHERE Id = :PageContractId Limit 1];
this.setCon = new ApexPages.StandardSetController( [SELECT AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate FROM Asset WHERE last_contract_number__c = :C.Name Limit 1000] );
}
else If ( PageAccountId <> NULL )
{
this.setCon = new ApexPages.StandardSetController( [SELECT AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate FROM Asset WHERE AccountId = :PageAccountId Limit 1000] );
}
}
If ( GetAccount.AccountId <> NULL && GetContract.Name == NULL )
{
this.setCon = new ApexPages.StandardSetController( [SELECT AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate FROM Asset WHERE AccountId = :GetAccount.AccountId Limit 1000] );
}
Else If ( GetContract.Name <> NULL && GetAccount.AccountId == NULL )
{
this.setCon = new ApexPages.StandardSetController( [SELECT AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate FROM Asset WHERE last_contract_number__c = :GetContract.Name Limit 1000] );
}
Else If ( GetAccount.AccountId <> NULL && GetContract.Name <> NULL )
{
this.setCon = new ApexPages.StandardSetController( [SELECT AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate FROM Asset WHERE AccountId = :GetAccount.AccountId and last_contract_number__c = :GetContract.Name Limit 1000] );
}
this.setCon.setpageNumber(1);
this.setCon.setPageSize(10);
}
/*
* handle item selected
*/
public void doSelectItem(){
this.selectedContactIds.add(this.contextItem);
}
/*
* handle item deselected
*/
public void doDeselectItem(){
this.selectedContactIds.remove(this.contextItem);
}
/*
* return count of selected items
*/
public Integer getSelectedCount(){
return this.selectedContactIds.size();
}
/*
* advance to next page
*/
public void doNext(){
if(this.setCon.getHasNext())
this.setCon.next();
}
/*
* advance to previous page
*/
public void doPrevious(){
if(this.setCon.getHasPrevious())
this.setCon.previous();
}
//public List<CCWRowItem> rows = new List<CCWRowItem>();
public List<CCWRowItem> rows {get; set;}
/*
* return current page of groups
*/
public List<CCWRowItem> getContacts(){
rows = new List<CCWRowItem>();
for(sObject r : this.setCon.getRecords()){
Asset c = (Asset)r;
CCWRowItem row = new CCWRowItem(c);
if(this.selectedContactIds.contains(c.Id)){
row.IsSelected=true;
}
else{
row.IsSelected=false;
}
rows.add(row);
}
return rows;
}
// Store Selected Records to Object/Table
public void processSelected() {
selectedAssets = new List<Asset>();
list<Temp_Assets__c> TempAssetList = new list<Temp_Assets__c>();
for(CCWRowItem wrapAssetObj : rows ) {
if(wrapAssetObj.IsSelected == true) {
selectedAssets.add(wrapAssetObj.tContact);
}
}
Account ResellerAct;
Account DistributorAct;
Opportunity Oppt;
for(Asset Act : selectedAssets)
{
Temp_Assets__c TempAsset = new Temp_Assets__c();
TempAsset.Name = 'Sudhir';
TempAsset.AccountId__c = Act.AccountId;
TempAsset.Product__c = Act.Product2Id;
TempAsset.Serial_Number__c = Act.SerialNumber;
TempAsset.Last_Contract_Number__c = Act.last_contract_number__c;
TempAsset.Service_Start_Date__c = Act.Service_Start_Date_Min__c;
TempAsset.Service_End_Date__c = Act.Service_End_Date_Max__c;
//TempAsset.Service_End_Date__c = maxDate;
TempAsset.Install_Date__c = Act.InstallDate;
If (GetReseller.AccountId <> NULL)
{
ResellerAct = [ SELECT Id FROM Account WHERE ID = :GetReseller.AccountId Limit 1];
TempAsset.Reseller__c = ResellerAct.Id;
}
If (GetDistributor.AccountId <> NULL )
{
DistributorAct = [ SELECT Id FROM Account WHERE ID = :GetDistributor.AccountId Limit 1];
TempAsset.Distributor__c = DistributorAct.Id;
}
If ( GetOpportunity.Opportunity__c <> NULL )
{
Oppt = [SELECT Id FROM Opportunity WHERE ID = :GetOpportunity.Opportunity__c Limit 1];
TempAsset.Existing_Opportunity__c = Oppt.Id;
}
TempAsset.Incumbent_Reseller__c = IncumbentReseller;
TempAsset.Education__c = Education;
TempAsset.Expiry_Date__c = GetExpireDate.Expire_Date__c;
TempAsset.New_Opportunity__c = GetNewOpportunity.New_Opportunity__c;
TempAsset.Expiry_Term__c = ExpireTerms;
//Add the selected Assets to the List
TempAssetList.add(TempAsset);
}
Insert TempAssetList;
}
/*
* return whether previous page exists
*/
public Boolean getHasPrevious(){
return this.setCon.getHasPrevious();
}
/*
* return whether next page exists
*/
public Boolean getHasNext(){
return this.setCon.getHasNext();
}
/*
* return page number
*/
public Integer getPageNumber(){
return this.setCon.getPageNumber();
}
/*
* return total pages
*/
Public Integer getTotalPages(){
Decimal totalSize = this.setCon.getResultSize();
Decimal pageSize = this.setCon.getPageSize();
Decimal pages = totalSize/pageSize;
return (Integer)pages.round(System.RoundingMode.CEILING);
}
/*
* helper class that represents a row
*/
public with sharing class CCWRowItem{
public Asset tContact{get;set;}
public Boolean IsSelected{get;set;}
public CCWRowItem(Asset c){
this.tContact=c;
this.IsSelected=false;
}
}
}
Visual Force
<apex:page controller="CCW_ContactPaginationController" showHeader="false" sidebar="false" readOnly="false" cache="false">
<script type="text/javascript">
/*
* function to handle checkbox selection
*/
function doCheckboxChange(cb,itemId){
if(cb.checked==true){
aSelectItem(itemId);
}
else{
aDeselectItem(itemId);
}
}
</script>
<apex:sectionHeader subtitle="Create Renewal Quote" title="Meru Networks"/>
<apex:form >
<apex:pageBlock >
<apex:pageBlockButtons >
<apex:commandButton value="Save Records" action="{!processSelected}"/>
</apex:pageBlockButtons>
<apex:pageBlockSection title="Install Base Report" id="mpb" collapsible="true" columns="1">
<!-- handle selected item -->
<apex:actionFunction name="aSelectItem" action="{!doSelectItem}" rerender="mpb">
<apex:param name="contextItem" value="" assignTo="{!contextItem}"/>
</apex:actionFunction>
<!-- handle deselected item -->
<apex:actionFunction name="aDeselectItem" action="{!doDeselectItem}" rerender="mpb">
<apex:param name="contextItem" value="" assignTo="{!contextItem}"/>
</apex:actionFunction>
<!-- table of data -->
<apex:pageBlockTable title="Assets" value="{!Contacts}" var="c">
<apex:column >
<apex:facet name="header">Action</apex:facet>
<apex:inputCheckbox value="{!c.IsSelected}" onchange="doCheckboxChange(this,'{!c.tContact.Id}')"/>
</apex:column>
<apex:column value="{!c.tContact.AccountId}"/>
<apex:column value="{!c.tContact.Product2Id}"/>
<apex:column value="{!c.tContact.SerialNumber}"/>
<apex:column value="{!c.tContact.last_contract_number__c}"/>
<apex:column value="{!c.tContact.Service_Start_Date_Min__c}"/>
<apex:column value="{!c.tContact.Service_End_Date_Max__c}"/>
<apex:column value="{!c.tContact.InstallDate}"/>
</apex:pageBlockTable>
<apex:pageBlockSection collapsible="false" columns="4">
<!-- count of selected items -->
<apex:outputLabel value="[{!selectedCount} records selected]" />
<apex:outputLabel value=" (page {!pageNumber} of {!totalPages}) " />
<!-- next, previous and page info -->
<apex:commandLink action="{!doPrevious}" rendered="{!hasPrevious}" value="Previous" />
<apex:outputLabel rendered="{!NOT(hasPrevious)}" value="Previous" />
<apex:commandLink action="{!doNext}" rendered="{!hasNext}" value="Next" />
<apex:outputLabel rendered="{!NOT(hasNext)}" value="Next" />
</apex:pageBlockSection>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Thanks
Sudhir
Integer currentPageNumber = setCon.getPageNumber();
setCon.setpageNumber(1);
while(true){
List<Asset> TempAssetLists = (List<Asset>)setCon.getRecords();
for(Asset assetIns : TempAssetLists ) {
if(this.selectedContactIds.contains(assetIns.Id)){
selectedAssets.add(assetIns);
}
}
if(setCon.gethasNext()){
setCon.next();
}
else{
break;
}
}
setCon.setpageNumber(currentPageNumber);
All Answers
Check if selectedContactIds contains the id of selected contacts when you select and click previous button.
Hi Swati,
It containts Id. Please suggest me how to modify this code so that all the selected page records must be saved
Thanks
Sudhir
As you suggesed I added system.debug I am able to see all 4 selected records below.
USER_DEBUG|[164]|DEBUG|selectedContactIds: {02i11000000GkbAAAS, 02i11000000GkwcAAC, 02i11000000GlW8AAK, 02i11000000GpLOAA0
Thanks
Sudhir
Long story short, follow the approach as mentioned in the below article
http://blog.cloudclickware.com/2013/04/04/list-pagination-and-record-selection-with-visualforce/
for(sObject r : this.setCon.getRecords()){
Asset c = (Asset)r;
system.debug('c.Id: '+c.id);
Hi Swati,
It is printing all the 14 ID's in system.debug log these are the records id that are displayed.
Thanks
Sudhir
Hi Ramu,
Can you give me a example how to add tempoary set collection in code and let me know.
Thanks
Sudhir
Hi Swati,
Only two records matched.
c.id
02i11000000GillAAC
02i11000000GjCmAAK
02i11000000GgyNAAS
02i11000000GkbAAAS
02i11000000GjdbAAC
02i11000000GkpYAAS
02i11000000GlW8AAK
02i11000000Gkh5AAC
02i11000000GmP4AAK
02i11000000GhykAAC
selectedContactIds
{02i11000000GgyNAAS, 02i11000000GkwcAAC, 02i11000000GlW8AAK, 02i11000000GpLOAA0}
Thanks
Sudhir
Issue is I think as pagination is happening only that selected records are displayed and matched and it is not happening with the previous selected records.
Please suggest me how to fix this issue.
Thanks
Sudhir
if(this.selectedContactIds.contains(c.Id)){
row.IsSelected=true;
}
else{
row.IsSelected=false;
}
Hi Swati,
How set make isSelected as true for previous selected page. Please give me a example
Thanks
Sudhir
<apex:actionfunction name="runonce" action="{!doselectitem}" rerender="mpb,summarysection" status="status">
<apex:param name="firstparam" assignTo="{!Selected_Recordid}" value=""/>
<apex:param name="secondparam" assignTo="{!Checkbox_status}" value=""/>
</apex:actionfunction>
<apex:column >
<apex:facet name="header">Action</apex:facet>
<apex:inputCheckbox value="{!c.IsSelected}" onchange="runonce('{!c.tContact.Id}',this.checked)"/>
</apex:column>
Controller :
Public String Selected_Recordid{get;set;}
Public boolean Checkbox_status{get;set;}
public void doSelectItem(){
if(Checkbox_status==true){
this.selectedIds.add(this.Selected_Recordid);
Stats();
}
else{
this.selectedIds.remove(this.Selected_Recordid);
Stats();
}
}
** selectedIds is the set collection variable in my code
Hope this helps !!
Hi Swati,
Problem I am facing is it will insert only the currect page selected rows if I have selected previous page selected rows these are not getting stored.
Thanks
Sudhir
setCon.setpageNumber(1);
while(true){
List<CCWRowItem> tempRows = setCon.getRecords();
for(CCWRowItem wrapAssetObj : tempRows ) {
if(this.selectedContactIds.contains(wrapAssetObj.tContact.Id)){
selectedAssets.add(wrapAssetObj.tContact);
}
}
if(setCon.hasNext()){
setCon.next();
}
else{
break;
}
}
Thanks for your code. I modifed Visualforce as you mentioned I didnt get no errors.
I am getting error in controller
Error: Compile Error: Variable does not exist: selectedids at line 103 column 9
Controller
public with sharing class CCW_ContactPaginationController {
//URL Passing Parameters.
String PageContractId = ApexPages.currentPage().getParameters().get('ContractId');
String PageAccountId = ApexPages.currentPage().getParameters().get('AccountId');
public Asset GetAccount{get;set;}
public Asset GetContract{get;set;}
public Asset GetExpireDate{get;set;}
public Asset GetReseller{get;set;}
public Asset GetDistributor{get;set;}
public Boolean IncumbentReseller{get;set;}
public Boolean Education{get;set;}
public Asset GetOpportunity{get;set;}
public Asset GetNewOpportunity{get;set;}
public String ExpireTerms{get;set;}
//Our collection to class/wrapper objects wrapAsset
public List<CCWRowItem> wrapAssetList {get; set;}
public List<Asset> selectedAssets{get;set;}
/*
* item in context from the page
*/
public String contextItem{get;set;}
/*
* set controller
*/
private ApexPages.StandardSetController setCon;
/*
* the contact ids selected by the user
*/
private Set<Id> selectedContactIds;
/*
* constructor
*/
public CCW_ContactPaginationController ()
{
GetAccount = new Asset(); //Get Account Id from Page
GetContract = new Asset(); //Get Contract Name from Page
GetExpireDate = new Asset(); // Date Picker
GetReseller = new Asset();
GetDistributor = new Asset();
GetOpportunity = new Asset(); // Get Opportunity Id
GetNewOpportunity = new Asset(); // Get New Opportunity Name
fetch_data();
}
// public List<Asset> Asset_yourObjList{get;set;}
public void fetch_data ()
{
//init variable
this.selectedContactIds= new Set<Id>();
//gather data set
If ( GetAccount.AccountId == NULL || GetContract.Name == NULL )
{
If ( PageContractId <> NULL )
{
Contract C;
C = [SELECT Name FROM Contract WHERE Id = :PageContractId Limit 1];
this.setCon = new ApexPages.StandardSetController( [SELECT AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate FROM Asset WHERE last_contract_number__c = :C.Name Limit 1000] );
}
else If ( PageAccountId <> NULL )
{
this.setCon = new ApexPages.StandardSetController( [SELECT AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate FROM Asset WHERE AccountId = :PageAccountId Limit 1000] );
}
}
If ( GetAccount.AccountId <> NULL && GetContract.Name == NULL )
{
this.setCon = new ApexPages.StandardSetController( [SELECT AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate FROM Asset WHERE AccountId = :GetAccount.AccountId Limit 1000] );
}
Else If ( GetContract.Name <> NULL && GetAccount.AccountId == NULL )
{
this.setCon = new ApexPages.StandardSetController( [SELECT AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate FROM Asset WHERE last_contract_number__c = :GetContract.Name Limit 1000] );
}
Else If ( GetAccount.AccountId <> NULL && GetContract.Name <> NULL )
{
this.setCon = new ApexPages.StandardSetController( [SELECT AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate FROM Asset WHERE AccountId = :GetAccount.AccountId and last_contract_number__c = :GetContract.Name Limit 1000] );
}
this.setCon.setpageNumber(1);
this.setCon.setPageSize(10);
}
Public String Selected_Recordid{get;set;}
Public boolean Checkbox_status{get;set;}
/*
* handle item selected
*/
public void doSelectItem(){
this.selectedContactIds.add(this.contextItem);
if(Checkbox_status==true){
this.selectedIds.add(this.Selected_Recordid);
Stats();
}
else{
this.selectedIds.remove(this.Selected_Recordid);
Stats();
}
}
/*
* handle item deselected
*/
public void doDeselectItem(){
this.selectedContactIds.remove(this.contextItem);
}
/*
* return count of selected items
*/
public Integer getSelectedCount(){
return this.selectedContactIds.size();
}
/*
* advance to next page
*/
public void doNext(){
if(this.setCon.getHasNext())
this.setCon.next();
}
/*
* advance to previous page
*/
public void doPrevious(){
if(this.setCon.getHasPrevious())
this.setCon.previous();
}
//public List<CCWRowItem> rows = new List<CCWRowItem>();
public List<CCWRowItem> rows {get; set;}
/*
* return current page of groups
*/
public List<CCWRowItem> getContacts(){
rows = new List<CCWRowItem>();
for(sObject r : this.setCon.getRecords()){
Asset c = (Asset)r;
system.debug('c.Id: '+c.id);
CCWRowItem row = new CCWRowItem(c);
if(this.selectedContactIds.contains(c.Id)){
row.IsSelected=true;
}
else{
row.IsSelected=false;
}
rows.add(row);
}
System.debug('selectedContactIds: '+selectedContactIds);
return rows;
}
// Store Selected Records to Object/Table
public void processSelected() {
selectedAssets = new List<Asset>();
list<Temp_Assets__c> TempAssetList = new list<Temp_Assets__c>();
for(CCWRowItem wrapAssetObj : rows ) {
if(wrapAssetObj.IsSelected == true) {
selectedAssets.add(wrapAssetObj.tContact);
}
}
/**********Added by Unnat*********************************/
//below code should only execute if Expiry term has a value
Date maxDate=Date.valueOf('2000-1-1');
//Calculate the maximum Date off of the selected dates
//if (Expiry_term !=null {
//finds the latest expiry date out of the selected assets
for (Asset assets: selectedAssets) {
if(assets.Service_End_Date_Max__c > maxDate) {
maxDate=assets.Service_End_Date_Max__c;
}
}
//There will be another condition to add the expiry term to the latest expiry date
/*if (expiry_term== '1 Year') {
maxDate=maxDate.addYears(1).addDays(1);
}
else if (expiry_term == '3 Year') {
maxDate=maxDate.addYears(3).addDays(1);
}
else if (expirty_term == '5 Year') {
maxDate=maxDate.addYears(5).addDays(1);
}
}
else {
maxDate= expiry_date;
} */
/****************Completed by Unnat*****************************/
Account ResellerAct;
Account DistributorAct;
Opportunity Oppt;
for(Asset Act : selectedAssets)
{
Temp_Assets__c TempAsset = new Temp_Assets__c();
TempAsset.Name = 'Sudhir';
TempAsset.AccountId__c = Act.AccountId;
TempAsset.Product__c = Act.Product2Id;
TempAsset.Serial_Number__c = Act.SerialNumber;
TempAsset.Last_Contract_Number__c = Act.last_contract_number__c;
TempAsset.Service_Start_Date__c = Act.Service_Start_Date_Min__c;
TempAsset.Service_End_Date__c = Act.Service_End_Date_Max__c;
//TempAsset.Service_End_Date__c = maxDate;
TempAsset.Install_Date__c = Act.InstallDate;
If (GetReseller.AccountId <> NULL)
{
ResellerAct = [ SELECT Id FROM Account WHERE ID = :GetReseller.AccountId Limit 1];
TempAsset.Reseller__c = ResellerAct.Id;
}
If (GetDistributor.AccountId <> NULL )
{
DistributorAct = [ SELECT Id FROM Account WHERE ID = :GetDistributor.AccountId Limit 1];
TempAsset.Distributor__c = DistributorAct.Id;
}
If ( GetOpportunity.Opportunity__c <> NULL )
{
Oppt = [SELECT Id FROM Opportunity WHERE ID = :GetOpportunity.Opportunity__c Limit 1];
TempAsset.Existing_Opportunity__c = Oppt.Id;
}
TempAsset.Incumbent_Reseller__c = IncumbentReseller;
TempAsset.Education__c = Education;
TempAsset.Expiry_Date__c = GetExpireDate.Expire_Date__c;
TempAsset.New_Opportunity__c = GetNewOpportunity.New_Opportunity__c;
TempAsset.Expiry_Term__c = ExpireTerms;
//Add the selected Assets to the List
TempAssetList.add(TempAsset);
}
Insert TempAssetList;
}
/*
* return whether previous page exists
*/
public Boolean getHasPrevious(){
return this.setCon.getHasPrevious();
}
/*
* return whether next page exists
*/
public Boolean getHasNext(){
return this.setCon.getHasNext();
}
/*
* return page number
*/
public Integer getPageNumber(){
return this.setCon.getPageNumber();
}
/*
* return total pages
*/
Public Integer getTotalPages(){
Decimal totalSize = this.setCon.getResultSize();
Decimal pageSize = this.setCon.getPageSize();
Decimal pages = totalSize/pageSize;
return (Integer)pages.round(System.RoundingMode.CEILING);
}
/*
* helper class that represents a row
*/
public with sharing class CCWRowItem{
public Asset tContact{get;set;}
public Boolean IsSelected{get;set;}
public CCWRowItem(Asset c){
this.tContact=c;
this.IsSelected=false;
}
}
}
Thanks Ramu,
Stats(); method does not exist in controller
Error: Compile Error: Method does not exist or incorrect signature: Stats() at line 104 column 9
Thanks
Sudhir
Hi Swati,
Where to add this code in controller
setCon.setpageNumber(1);
while(true){
List<CCWRowItem> tempRows = setCon.getRecords();
for(CCWRowItem wrapAssetObj : tempRows ) {
if(this.selectedContactIds.contains(wrapAssetObj.tContact.Id)){
selectedAssets.add(wrapAssetObj.tContact);
}
}
if(setCon.hasNext()){
setCon.next();
}
else{
break;
}
}
Please advice.
Thanks
Sudhir
I get this error Error: Compile Error: Illegal assignment from LIST<SObject> to LIST<CCW_ContactPaginationController.CCWRowItem> at line 183 column 5
Line 183 is List<CCWRowItem> tempRows = setCon.getRecords();
// Store Selected Records to Object/Table
public void processSelected() {
selectedAssets = new List<Asset>();
list<Temp_Assets__c> TempAssetList = new list<Temp_Assets__c>();
/* for(CCWRowItem wrapAssetObj : rows ) {
if(wrapAssetObj.IsSelected == true) {
selectedAssets.add(wrapAssetObj.tContact);
}
} */
setCon.setpageNumber(1);
while(true){
List<CCWRowItem> tempRows = setCon.getRecords();
for(CCWRowItem wrapAssetObj : tempRows ) {
if(this.selectedContactIds.contains(wrapAssetObj.tContact.Id)){
selectedAssets.add(wrapAssetObj.tContact);
}
}
if(setCon.hasNext()){
setCon.next();
}
else{
break;
}
}
Account ResellerAct;
Account DistributorAct;
Opportunity Oppt;
for(Asset Act : selectedAssets)
{
Temp_Assets__c TempAsset = new Temp_Assets__c();
TempAsset.Name = 'Sudhir';
TempAsset.AccountId__c = Act.AccountId;
TempAsset.Product__c = Act.Product2Id;
TempAsset.Serial_Number__c = Act.SerialNumber;
TempAsset.Last_Contract_Number__c = Act.last_contract_number__c;
TempAsset.Service_Start_Date__c = Act.Service_Start_Date_Min__c;
TempAsset.Service_End_Date__c = Act.Service_End_Date_Max__c;
//TempAsset.Service_End_Date__c = maxDate;
TempAsset.Install_Date__c = Act.InstallDate;
If (GetReseller.AccountId <> NULL)
{
ResellerAct = [ SELECT Id FROM Account WHERE ID = :GetReseller.AccountId Limit 1];
TempAsset.Reseller__c = ResellerAct.Id;
}
If (GetDistributor.AccountId <> NULL )
{
DistributorAct = [ SELECT Id FROM Account WHERE ID = :GetDistributor.AccountId Limit 1];
TempAsset.Distributor__c = DistributorAct.Id;
}
If ( GetOpportunity.Opportunity__c <> NULL )
{
Oppt = [SELECT Id FROM Opportunity WHERE ID = :GetOpportunity.Opportunity__c Limit 1];
TempAsset.Existing_Opportunity__c = Oppt.Id;
}
TempAsset.Incumbent_Reseller__c = IncumbentReseller;
TempAsset.Education__c = Education;
TempAsset.Expiry_Date__c = GetExpireDate.Expire_Date__c;
TempAsset.New_Opportunity__c = GetNewOpportunity.New_Opportunity__c;
TempAsset.Expiry_Term__c = ExpireTerms;
//Add the selected Assets to the List
TempAssetList.add(TempAsset);
}
Insert TempAssetList;
}
Hi Ramu,
Modified your code and added still I am able to save only two records previous page selected records am not able to save.
Thanks
Sudhir
List<CCWRowItem> tempRows = (List<CCWRowItem>) setCon.getRecords();
Modified I get below error
Error: Compile Error: Incompatible types since an instance of LIST<SObject> is never an instance of LIST<CCW_ContactPaginationController.CCWRowItem> at line 183 column 35
Hi Ramu,
Do I have to make any changes in your code please advice.
Thanks
Sudhir
setCon.setpageNumber(1);
while(true){
List<Asset> tempAssetList = (List<Asset>)setCon.getRecords();
for(Asset assetIns : tempAssetList ) {
if(this.selectedContactIds.contains(assetIns.Id)){
selectedAssets.add(assetIns);
}
}
if(setCon.hasNext()){
setCon.next();
}
else{
break;
}
}
I get this error now
Error: Compile Error: Method does not exist or incorrect signature: [ApexPages.StandardSetController].hasNext() at line 189 column 6
i.e if(setCon.hasNext()){
setCon.next();
}
else{
break;
}
I comment this section But I am not able to insert records now I modifed your code as below I renamed the variable to TempAssetListwhich is highlighted below. Please check
// Store Selected Records to Object/Table
public void processSelected() {
selectedAssets = new List<Asset>();
list<Temp_Assets__c> TempAssetList = new list<Temp_Assets__c>();
/* for(CCWRowItem wrapAssetObj : rows ) {
if(wrapAssetObj.IsSelected == true) {
selectedAssets.add(wrapAssetObj.tContact);
}
} */
setCon.setpageNumber(1);
while(true){
List<Asset> TempAssetLists = (List<Asset>)setCon.getRecords();
for(Asset assetIns : TempAssetLists ) {
if(this.selectedContactIds.contains(assetIns.Id)){
selectedAssets.add(assetIns);
}
}
/* if(setCon.hasNext()){
setCon.next();
}
else{
break;
} */
}
Account ResellerAct;
Account DistributorAct;
Opportunity Oppt;
for(Asset Act : selectedAssets)
{
Temp_Assets__c TempAsset = new Temp_Assets__c();
TempAsset.Name = 'Sudhir';
TempAsset.AccountId__c = Act.AccountId;
TempAsset.Product__c = Act.Product2Id;
TempAsset.Serial_Number__c = Act.SerialNumber;
TempAsset.Last_Contract_Number__c = Act.last_contract_number__c;
TempAsset.Service_Start_Date__c = Act.Service_Start_Date_Min__c;
TempAsset.Service_End_Date__c = Act.Service_End_Date_Max__c;
//TempAsset.Service_End_Date__c = maxDate;
TempAsset.Install_Date__c = Act.InstallDate;
If (GetReseller.AccountId <> NULL)
{
ResellerAct = [ SELECT Id FROM Account WHERE ID = :GetReseller.AccountId Limit 1];
TempAsset.Reseller__c = ResellerAct.Id;
}
If (GetDistributor.AccountId <> NULL )
{
DistributorAct = [ SELECT Id FROM Account WHERE ID = :GetDistributor.AccountId Limit 1];
TempAsset.Distributor__c = DistributorAct.Id;
}
If ( GetOpportunity.Opportunity__c <> NULL )
{
Oppt = [SELECT Id FROM Opportunity WHERE ID = :GetOpportunity.Opportunity__c Limit 1];
TempAsset.Existing_Opportunity__c = Oppt.Id;
}
TempAsset.Incumbent_Reseller__c = IncumbentReseller;
TempAsset.Education__c = Education;
TempAsset.Expiry_Date__c = GetExpireDate.Expire_Date__c;
TempAsset.New_Opportunity__c = GetNewOpportunity.New_Opportunity__c;
TempAsset.Expiry_Term__c = ExpireTerms;
//Add the selected Assets to the List
TempAssetList.add(TempAsset);
}
Insert TempAssetList;
}
Thanks
Sudhir
Thanks Swati I am able to save 4 records after saving records page show only one record on screen It is going to last page Please make to main on same page.
Thanks
Sudhir
Integer currentPageNumber = setCon.getPageNumber();
setCon.setpageNumber(1);
while(true){
List<Asset> TempAssetLists = (List<Asset>)setCon.getRecords();
for(Asset assetIns : TempAssetLists ) {
if(this.selectedContactIds.contains(assetIns.Id)){
selectedAssets.add(assetIns);
}
}
if(setCon.gethasNext()){
setCon.next();
}
else{
break;
}
}
setCon.setpageNumber(currentPageNumber);
Hi Swati,
If possible after clicking on save can you suggest me how to close the page even this is fine.
Thanks
Sudhir
Hi Swati,
You are GENIOUS in SFDC Thank You Very Much for you help It was a great help for me to resolve this issue.
THANK YOU VERY MUCH YOU ARE GENIOUS
Thanks
Sudhir
I need a help in same controller I want to add checkbox on each row and capture that inside custom object. Please suggest me how to capture checked checkbox value.
Let me know if you need seprate question to be posted in forum
Thanks
Sudhir
It is not releated to Asset I just need to add a column called Bundle Support which is a checkbox and if user check or uncheck I need to capture this boolean value inside custom object.
For exiting page I just need to add one more column which is a checkbox and capture this value
Thanks
Sudhir
For example, when user checked some of the checkboxes and save it. And when user visits page again then the checkbox which was checked previously should be shown as checked. This is possible only if there is some relation between asset may be some common field or something.
Lets do like this I have created a custom field in asset object know as Bundle_Support__c this will be a checkbox dispalyed in visualforce page.
When user check or uncheck based on that value has to be insert inside custom object.
I tried as mentioned below but i get following error.
System.VisualforceException: Modified rows exist in the records collection!
I just need checkbox on eachrow which every is checked it has to be stored simple :) Please suggest me how to do
Controller
public with sharing class CCW_ContactPaginationController {
//URL Passing Parameters.
String PageContractId = ApexPages.currentPage().getParameters().get('ContractId');
String PageAccountId = ApexPages.currentPage().getParameters().get('AccountId');
public Asset GetAccount{get;set;}
public Asset GetContract{get;set;}
public Asset GetExpireDate{get;set;}
public Asset GetReseller{get;set;}
public Asset GetDistributor{get;set;}
public Boolean IncumbentReseller{get;set;}
public Boolean Education{get;set;}
public Asset GetOpportunity{get;set;}
public Asset GetNewOpportunity{get;set;}
public String ExpireTerms{get;set;}
public Boolean BundSuprt{get;set;}
public Boolean Skilled {get;set;}
//Our collection to class/wrapper objects wrapAsset
public List<CCWRowItem> wrapAssetList {get; set;}
public List<Asset> selectedAssets{get;set;}
/*
* item in context from the page
*/
public String contextItem{get;set;}
/*
* set controller
*/
private ApexPages.StandardSetController setCon;
/*
* the contact ids selected by the user
*/
private Set<Id> selectedContactIds;
/*
* constructor
*/
public CCW_ContactPaginationController ()
{
GetAccount = new Asset(); //Get Account Id from Page
GetContract = new Asset(); //Get Contract Name from Page
GetExpireDate = new Asset(); // Date Picker
GetReseller = new Asset();
GetDistributor = new Asset();
GetOpportunity = new Asset(); // Get Opportunity Id
GetNewOpportunity = new Asset(); // Get New Opportunity Name
fetch_data();
}
// public List<Asset> Asset_yourObjList{get;set;}
public void fetch_data ()
{
//init variable
this.selectedContactIds= new Set<Id>();
//gather data set
If ( GetAccount.AccountId == NULL || GetContract.Name == NULL )
{
If ( PageContractId <> NULL )
{
Contract C;
C = [SELECT Name FROM Contract WHERE Id = :PageContractId Limit 1];
this.setCon = new ApexPages.StandardSetController( [SELECT AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE last_contract_number__c = :C.Name Order by Service_End_Date_Max__c Desc Limit 1000] );
}
else If ( PageAccountId <> NULL )
{
this.setCon = new ApexPages.StandardSetController( [SELECT AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE AccountId = :PageAccountId Order by Service_End_Date_Max__c Desc Limit 1000] );
}
}
If ( GetAccount.AccountId <> NULL && GetContract.Name == NULL )
{
this.setCon = new ApexPages.StandardSetController( [SELECT AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE AccountId = :GetAccount.AccountId Order by Service_End_Date_Max__c Desc Limit 1000] );
}
Else If ( GetContract.Name <> NULL && GetAccount.AccountId == NULL )
{
this.setCon = new ApexPages.StandardSetController( [SELECT AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE last_contract_number__c = :GetContract.Name Order by Service_End_Date_Max__c Desc Limit 1000] );
}
Else If ( GetAccount.AccountId <> NULL && GetContract.Name <> NULL )
{
this.setCon = new ApexPages.StandardSetController( [SELECT AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE AccountId = :GetAccount.AccountId and last_contract_number__c = :GetContract.Name Order by Service_End_Date_Max__c Desc Limit 1000] );
}
this.setCon.setpageNumber(1);
this.setCon.setPageSize(10);
}
/*
* handle item selected
*/
public void doSelectItem(){
this.selectedContactIds.add(this.contextItem);
}
/*
* handle item deselected
*/
public void doDeselectItem(){
this.selectedContactIds.remove(this.contextItem);
}
/*
* return count of selected items
*/
public Integer getSelectedCount(){
return this.selectedContactIds.size();
}
/*
* advance to next page
*/
public void doNext(){
if(this.setCon.getHasNext())
this.setCon.next();
}
/*
* advance to previous page
*/
public void doPrevious(){
if(this.setCon.getHasPrevious())
this.setCon.previous();
}
//public List<CCWRowItem> rows = new List<CCWRowItem>();
public List<CCWRowItem> rows {get; set;}
/*
* return current page of groups
*/
public List<CCWRowItem> getContacts(){
rows = new List<CCWRowItem>();
for(sObject r : this.setCon.getRecords()){
Asset c = (Asset)r;
CCWRowItem row = new CCWRowItem(c);
if(this.selectedContactIds.contains(c.Id)){
row.IsSelected=true;
}
else{
row.IsSelected=false;
}
rows.add(row);
}
return rows;
}
// Store Selected Records to Object/Table
public void processSelected() {
Integer currentPageNumber = setCon.getPageNumber();
selectedAssets = new List<Asset>().deepClone(true, true, true);
list<Temp_Assets__c> TempAssetList = new list<Temp_Assets__c>();
/* for(CCWRowItem wrapAssetObj : rows ) {
if(wrapAssetObj.IsSelected == true) {
selectedAssets.add(wrapAssetObj.tContact);
}
} */
setCon.setpageNumber(1);
while(true){
List<Asset> TempAssetLists = (List<Asset>)setCon.getRecords().deepClone(true, true, true);
for(Asset assetIns : TempAssetLists ) {
if(this.selectedContactIds.contains(assetIns.Id)){
selectedAssets.add(assetIns);
}
}
if(setCon.getHasNext()){
setCon.next();
}
else{
break;
}
}
Account ResellerAct;
Account DistributorAct;
Opportunity Oppt;
for(Asset Act : selectedAssets)
{
Temp_Assets__c TempAsset = new Temp_Assets__c();
TempAsset.Name = 'Sudhir';
TempAsset.AccountId__c = Act.AccountId;
TempAsset.Product__c = Act.Product2Id;
TempAsset.Serial_Number__c = Act.SerialNumber;
TempAsset.Last_Contract_Number__c = Act.last_contract_number__c;
TempAsset.Service_Start_Date__c = Act.Service_Start_Date_Min__c;
TempAsset.Service_End_Date__c = Act.Service_End_Date_Max__c;
TempAsset.Install_Date__c = Act.InstallDate;
If (GetReseller.AccountId <> NULL)
{
ResellerAct = [ SELECT Id FROM Account WHERE ID = :GetReseller.AccountId Limit 1];
TempAsset.Reseller__c = ResellerAct.Id;
}
If (GetDistributor.AccountId <> NULL )
{
DistributorAct = [ SELECT Id FROM Account WHERE ID = :GetDistributor.AccountId Limit 1];
TempAsset.Distributor__c = DistributorAct.Id;
}
If ( GetOpportunity.Opportunity__c <> NULL )
{
Oppt = [SELECT Id FROM Opportunity WHERE ID = :GetOpportunity.Opportunity__c Limit 1];
TempAsset.Existing_Opportunity__c = Oppt.Id;
}
TempAsset.Incumbent_Reseller__c = IncumbentReseller;
TempAsset.Education__c = Education;
TempAsset.Expiry_Date__c = GetExpireDate.Expire_Date__c;
TempAsset.New_Opportunity__c = GetNewOpportunity.New_Opportunity__c;
TempAsset.Expiry_Term__c = ExpireTerms;
TempAsset.Bundle_Support__c = Act.Bundle_Support__c;
//Add the selected Assets to the List
TempAssetList.add(TempAsset);
}
Insert TempAssetList;
setCon.setpageNumber(currentPageNumber);
}
/*
* return whether previous page exists
*/
public Boolean getHasPrevious(){
return this.setCon.getHasPrevious();
}
/*
* return whether next page exists
*/
public Boolean getHasNext(){
return this.setCon.getHasNext();
}
/*
* return page number
*/
public Integer getPageNumber(){
return this.setCon.getPageNumber();
}
/*
* return total pages
*/
Public Integer getTotalPages(){
Decimal totalSize = this.setCon.getResultSize();
Decimal pageSize = this.setCon.getPageSize();
Decimal pages = totalSize/pageSize;
return (Integer)pages.round(System.RoundingMode.CEILING);
}
/*
* helper class that represents a row
*/
public with sharing class CCWRowItem{
public Asset tContact{get;set;}
public Boolean IsSelected{get;set;}
public Boolean BundelSelected{get;set;}
public CCWRowItem(Asset c){
this.tContact=c;
this.IsSelected=false;
this.BundelSelected=false;
}
}
}
Visual Force
<!-- table of data -->
<apex:pageBlockTable title="Assets" value="{!Contacts}" var="c" id="reportblocktable">
<apex:column >
<apex:facet name="header">Action</apex:facet>
<apex:inputCheckbox value="{!c.IsSelected}" onclick="doCheckboxChange(this,'{!c.tContact.Id}')"/>
</apex:column>
<apex:column >
<apex:facet name="header">Bundle Support</apex:facet>
<apex:inputCheckbox value="{!c.tContact.Bundle_Support__c}" />
</apex:column>
<apex:column value="{!c.tContact.AccountId}"/>
<apex:column value="{!c.tContact.Product2Id}"/>
<apex:column value="{!c.tContact.SerialNumber}"/>
<apex:column value="{!c.tContact.last_contract_number__c}"/>
<apex:column value="{!c.tContact.Service_Start_Date_Min__c}"/>
<apex:column value="{!c.tContact.Service_End_Date_Max__c}"/>
<apex:column value="{!c.tContact.InstallDate}"/>
<apex:inlineEditSupport event="ondblClick"
showOnEdit="saveButton,cancelButton" hideOnEdit="editButton" />
</apex:pageBlockTable>
Thanks for your help on pagination I need am getting below error in controller please suggest me how to fix this issue
System.NullPointerException: Attempt to de-reference a null object
I get below error and line 97 and line 60 from controller. I am doing pagination using wrapper class
Class.CCW_ContactPaginationController.fetch_data: line 97, column 1
Class.CCW_ContactPaginationController.<init>: line 60, column 1
public with sharing class CCW_ContactPaginationController {
//URL Passing Parameters.
String PageContractId = ApexPages.currentPage().getParameters().get('ContractId');
String PageAccountId = ApexPages.currentPage().getParameters().get('AccountId');
public Asset GetAccount{get;set;}
public Asset GetContract{get;set;}
public Asset GetExpireDate{get;set;}
public Asset GetReseller{get;set;}
public Asset GetDistributor{get;set;}
public String IncumbentReseller{get;set;}
public String Education{get;set;}
public Asset GetOpportunity{get;set;}
public Asset GetNewOpportunity{get;set;}
public String ExpireTerms{get;set;}
public boolean bundsprt{get;set;}
//Our collection to class/wrapper objects wrapAsset
public List<CCWRowItem> wrapAssetList {get; set;}
public List<Asset> selectedAssets{get;set;}
/*
* item in context from the page
*/
public String contextItem{get;set;}
public String contextItem2{get;set;}
/*
* set controller
*/
private ApexPages.StandardSetController setCon;
/*
* the contact ids selected by the user
*/
private Set<Id> selectedContactIds;
private Set<Id> selectedContactIds2= new set<Id>();
/*
* constructor
*/
public CCW_ContactPaginationController ()
{
GetAccount = new Asset(); //Get Account Id from Page
GetContract = new Asset(); //Get Contract Name from Page
GetExpireDate = new Asset(); // Date Picker
GetReseller = new Asset();
GetDistributor = new Asset();
GetOpportunity = new Asset(); // Get Opportunity Id
GetNewOpportunity = new Asset(); // Get New Opportunity Name
oppreseller = new Opportunity();
fetch_data();
}
public void fetch_data ()
{
//init variable
this.selectedContactIds= new Set<Id>();
//gather data set
If ( GetAccount.AccountId == NULL || GetContract.Name == NULL )
{
If ( PageContractId <> NULL )
{
Contract C;
C = [SELECT Name FROM Contract WHERE Id = :PageContractId Limit 1];
this.setCon = new ApexPages.StandardSetController( [SELECT AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE last_contract_number__c = :C.Name Order by Service_End_Date_Max__c Desc Limit 1000] );
}
else If ( PageAccountId <> NULL )
{
this.setCon = new ApexPages.StandardSetController( [SELECT AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE AccountId = :PageAccountId Order by Service_End_Date_Max__c Desc Limit 1000] );
}
}
If ( GetAccount.AccountId <> NULL && GetContract.Name == NULL )
{
this.setCon = new ApexPages.StandardSetController( [SELECT AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE AccountId = :GetAccount.AccountId Order by Service_End_Date_Max__c Desc Limit 1000] );
}
Else If ( GetContract.Name <> NULL && GetAccount.AccountId == NULL )
{
this.setCon = new ApexPages.StandardSetController( [SELECT AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE last_contract_number__c = :GetContract.Name Order by Service_End_Date_Max__c Desc Limit 1000] );
}
Else If ( GetAccount.AccountId <> NULL && GetContract.Name <> NULL )
{
this.setCon = new ApexPages.StandardSetController( [SELECT AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE AccountId = :GetAccount.AccountId and last_contract_number__c = :GetContract.Name Order by Service_End_Date_Max__c Desc Limit 1000] );
}
this.setCon.setpageNumber(1);
this.setCon.setPageSize(25);
}
/*
* handle item selected
*/
public void doSelectItem(){
this.selectedContactIds.add(this.contextItem);
}
public void doSelectItem2(){
this.selectedContactIds2.add(this.contextItem2);
}
/*
* handle item deselected
*/
public void doDeselectItem(){
this.selectedContactIds.remove(this.contextItem);
}
public void doDeselectItem2(){
this.selectedContactIds2.remove(this.contextItem2);
}
/*
* return count of selected items
*/
public Integer getSelectedCount(){
return this.selectedContactIds.size();
}
/*
* advance to next page
*/
public void doNext(){
if(this.setCon.getHasNext())
this.setCon.next();
}
/*
* advance to previous page
*/
public void doPrevious(){
if(this.setCon.getHasPrevious())
this.setCon.previous();
}
//public List<CCWRowItem> rows = new List<CCWRowItem>();
public List<CCWRowItem> rows {get; set;}
/*
* return current page of groups
*/
public List<CCWRowItem> getContacts(){
rows = new List<CCWRowItem>();
for(sObject r : this.setCon.getRecords()){
Asset c = (Asset)r;
CCWRowItem row = new CCWRowItem(c);
if(this.selectedContactIds.contains(c.Id)){
row.IsSelected=true;
if (this.selectedContactIds2.contains(c.Id)){
row.BundelSelected=true;
bundsprt=true;
}
else {
row.BundelSelected=false;
bundsprt=false;
}
}
else {
row.IsSelected=false;
}
rows.add(row);
}
return rows;
}
// Store Selected Records to Object/Table
public void processSelected() {
Integer currentPageNumber = setCon.getPageNumber();
selectedAssets = new List<Asset>();
list<Temp_Assets__c> TempAssetList = new list<Temp_Assets__c>();
setCon.setpageNumber(1);
while(true){
List<Asset> TempAssetLists = (List<Asset>)setCon.getRecords();
for(Asset assetIns : TempAssetLists ) {
if(this.selectedContactIds.contains(assetIns.Id)){
selectedAssets.add(assetIns);
}
}
if(setCon.getHasNext()){
setCon.next();
}
else{
break;
}
}
Account ResellerAct;
Account DistributorAct;
Opportunity Oppt;
for(Asset Act : selectedAssets)
{
Temp_Assets__c TempAsset = new Temp_Assets__c();
TempAsset.Name = 'Sudhir';
TempAsset.AccountId__c = Act.AccountId;
TempAsset.Product__c = Act.Product2Id;
//Added by Unnat
TempAsset.Product_lookup__c= Act.Product2Id;
TempAsset.Serial_Number__c = Act.SerialNumber;
TempAsset.Last_Contract_Number__c = Act.last_contract_number__c;
TempAsset.Service_Start_Date__c = Act.Service_Start_Date_Min__c;
//TempAsset.Service_End_Date__c = Act.Service_End_Date_Max__c;
/***************Added by Unnat********************************************/
if (Act.Service_End_Date_Max__c != null) {
TempAsset.Service_End_Date__c = Act.Service_End_Date_Max__c;
}
else {
TempAsset.Service_End_Date__c = Act.InstallDate;
}
TempAsset.Install_Date__c = Act.InstallDate;
If (GetReseller.AccountId <> NULL)
{
ResellerAct = [ SELECT Id FROM Account WHERE ID = :GetReseller.AccountId Limit 1];
TempAsset.Reseller__c = ResellerAct.Id;
}
If (GetDistributor.AccountId <> NULL )
{
DistributorAct = [ SELECT Id FROM Account WHERE ID = :GetDistributor.AccountId Limit 1];
TempAsset.Distributor__c = DistributorAct.Id;
}
If ( GetOpportunity.Opportunity__c <> NULL )
{
Oppt = [SELECT Id FROM Opportunity WHERE ID = :GetOpportunity.Opportunity__c Limit 1];
TempAsset.Existing_Opportunity__c = Oppt.Id;
}
TempAsset.Incumbent_Reseller__c = IncumbentReseller;
TempAsset.Education__c = Education;
//TempAsset.Expiry_Date__c = GetExpireDate.Expire_Date__c;
TempAsset.Expiry_Date__c= maxDate;
TempAsset.New_Opportunity__c = GetNewOpportunity.New_Opportunity__c;
TempAsset.Expiry_Term__c = ExpireTerms;
/* Insert Bundel Checkbox Value */
if (this.selectedContactIds2.contains(Act.Id)){
bundsprt=true;
}
else {
bundsprt=false;
}
TempAsset.Bundle_Support__c = bundsprt;
System.debug('== Bundle Value is: ' + bundsprt);
//Add the selected Assets to the List
TempAssetList.add(TempAsset);
}
Insert TempAssetList;
setCon.setpageNumber(currentPageNumber);
}
/*
* return whether previous page exists
*/
public Boolean getHasPrevious(){
return this.setCon.getHasPrevious();
}
/*
* return whether next page exists
*/
public Boolean getHasNext(){
return this.setCon.getHasNext();
}
/*
* return page number
*/
public Integer getPageNumber(){
return this.setCon.getPageNumber();
}
/*
* return total pages
*/
Public Integer getTotalPages(){
Decimal totalSize = this.setCon.getResultSize();
Decimal pageSize = this.setCon.getPageSize();
Decimal pages = totalSize/pageSize;
return (Integer)pages.round(System.RoundingMode.CEILING);
}
/*
* helper class that represents a row
*/
public with sharing class CCWRowItem{
public Asset tContact{get;set;}
public Boolean IsSelected{get;set;}
public Boolean BundelSelected{get;set;}
public CCWRowItem(Asset c){
this.tContact=c;
this.IsSelected=false;
this.BundelSelected=false;
}
}
}
System.NullPointerException: Attempt to de-reference a null object
Error is coming when I navigate more 5 page after than i get this error when i click pagination
Thanks
Sudhir
You can add check that this.setCon != null.
Hi Swati,
I added like this I get Error: Compile Error: Expression cannot be a statement at line 97 column 9
this.setCon != null;
this.setCon.setpageNumber(1);
this.setCon.setPageSize(10);
Please suggest me where to add this condition
Thanks
Sudhir
add this condition now i am getting error in line 173
if ( this.setCon != null )
{
this.setCon.setpageNumber(1);
this.setCon.setPageSize(10);
}
line 173 is
public List<CCWRowItem> getContacts(){
rows = new List<CCWRowItem>();
for(sObject r : this.setCon.getRecords()){ // line 173
Asset c = (Asset)r;
CCWRowItem row = new CCWRowItem(c);
if(this.selectedContactIds.contains(c.Id)){
row.IsSelected=true;
if (this.selectedContactIds2.contains(c.Id)){
row.BundelSelected=true;
bundsprt=true;
}
else {
row.BundelSelected=false;
bundsprt=false;
}
}
else {
row.IsSelected=false;
}
rows.add(row);
}
return rows;
}
if(this.setCon != null){
this.setCon.setpageNumber(1);
this.setCon.setPageSize(10);
}
I added your condition where i got the error now in line 379 am getting now i am able to paginate more than 10 pages. Please suggest me how to fix this in controller
public with sharing class CCW_ContactPaginationController {
//URL Passing Parameters.
String PageContractId = ApexPages.currentPage().getParameters().get('ContractId');
String PageAccountId = ApexPages.currentPage().getParameters().get('AccountId');
public Asset GetAccount{get;set;}
public Asset GetContract{get;set;}
public Asset GetExpireDate{get;set;}
public Asset GetReseller{get;set;}
public Asset GetDistributor{get;set;}
public String IncumbentReseller{get;set;}
public String Education{get;set;}
public Asset GetOpportunity{get;set;}
public Asset GetNewOpportunity{get;set;}
public String ExpireTerms{get;set;}
public boolean bundsprt{get;set;}
public opportunity oppreseller {get;set;}
/* public list<Account> GetReseller(){
return [select id from account where Partner_Type__c = 'RESELLER'];
} */
//Our collection to class/wrapper objects wrapAsset
public List<CCWRowItem> wrapAssetList {get; set;}
public List<Asset> selectedAssets{get;set;}
/*
* item in context from the page
*/
public String contextItem{get;set;}
public String contextItem2{get;set;}
/*
* set controller
*/
private ApexPages.StandardSetController setCon;
/*
* the contact ids selected by the user
*/
private Set<Id> selectedContactIds;
private Set<Id> selectedContactIds2= new set<Id>();
/*
* constructor
*/
public CCW_ContactPaginationController ()
{
GetAccount = new Asset(); //Get Account Id from Page
GetContract = new Asset(); //Get Contract Name from Page
GetExpireDate = new Asset(); // Date Picker
GetReseller = new Asset();
GetDistributor = new Asset();
GetOpportunity = new Asset(); // Get Opportunity Id
GetNewOpportunity = new Asset(); // Get New Opportunity Name
oppreseller = new Opportunity();
fetch_data();
}
public void fetch_data ()
{
//init variable
this.selectedContactIds= new Set<Id>();
//gather data set
If ( GetAccount.AccountId == NULL || GetContract.Name == NULL )
{
If ( PageContractId <> NULL )
{
Contract C;
C = [SELECT Name FROM Contract WHERE Id = :PageContractId Limit 1];
this.setCon = new ApexPages.StandardSetController( [SELECT AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE last_contract_number__c = :C.Name Order by Service_End_Date_Max__c Desc Limit 1000] );
}
else If ( PageAccountId <> NULL )
{
this.setCon = new ApexPages.StandardSetController( [SELECT AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE AccountId = :PageAccountId Order by Service_End_Date_Max__c Desc Limit 1000] );
}
}
If ( GetAccount.AccountId <> NULL && GetContract.Name == NULL )
{
this.setCon = new ApexPages.StandardSetController( [SELECT AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE AccountId = :GetAccount.AccountId Order by Service_End_Date_Max__c Desc Limit 1000] );
}
Else If ( GetContract.Name <> NULL && GetAccount.AccountId == NULL )
{
this.setCon = new ApexPages.StandardSetController( [SELECT AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE last_contract_number__c = :GetContract.Name Order by Service_End_Date_Max__c Desc Limit 1000] );
}
Else If ( GetAccount.AccountId <> NULL && GetContract.Name <> NULL )
{
this.setCon = new ApexPages.StandardSetController( [SELECT AccountId,Product2Id,SerialNumber,last_contract_number__c,Service_Start_Date_Min__c, Service_End_Date_Max__c,InstallDate,Bundle_Support__c FROM Asset WHERE AccountId = :GetAccount.AccountId and last_contract_number__c = :GetContract.Name Order by Service_End_Date_Max__c Desc Limit 1000] );
}
if(this.setCon != null){
this.setCon.setpageNumber(1);
this.setCon.setPageSize(10);
}
}
/*
* handle item selected
*/
public void doSelectItem(){
this.selectedContactIds.add(this.contextItem);
}
public void doSelectItem2(){
this.selectedContactIds2.add(this.contextItem2);
}
/*
* handle item deselected
*/
public void doDeselectItem(){
this.selectedContactIds.remove(this.contextItem);
}
public void doDeselectItem2(){
this.selectedContactIds2.remove(this.contextItem2);
}
/*
* return count of selected items
*/
public Integer getSelectedCount(){
return this.selectedContactIds.size();
}
/*
* advance to next page
*/
public void doNext(){
if(this.setCon != null){
if(this.setCon.getHasNext())
this.setCon.next();
}
}
/*
* advance to previous page
*/
public void doPrevious(){
if(this.setCon != null){
if(this.setCon.getHasPrevious())
this.setCon.previous();
}
}
//public List<CCWRowItem> rows = new List<CCWRowItem>();
public List<CCWRowItem> rows {get; set;}
/*
* return current page of groups
*/
public List<CCWRowItem> getContacts(){
rows = new List<CCWRowItem>();
if(this.setCon != null){
for(sObject r : this.setCon.getRecords()){
Asset c = (Asset)r;
CCWRowItem row = new CCWRowItem(c);
if(this.selectedContactIds.contains(c.Id)){
row.IsSelected=true;
if (this.selectedContactIds2.contains(c.Id)){
row.BundelSelected=true;
bundsprt=true;
}
else {
row.BundelSelected=false;
bundsprt=false;
}
}
else {
row.IsSelected=false;
}
rows.add(row);
}
}
return rows;
}
// Store Selected Records to Object/Table
public void processSelected() {
Integer currentPageNumber = setCon.getPageNumber();
selectedAssets = new List<Asset>();
list<Temp_Assets__c> TempAssetList = new list<Temp_Assets__c>();
setCon.setpageNumber(1);
while(true){
List<Asset> TempAssetLists = (List<Asset>)setCon.getRecords();
for(Asset assetIns : TempAssetLists ) {
if(this.selectedContactIds.contains(assetIns.Id)){
selectedAssets.add(assetIns);
}
}
if(setCon.getHasNext()){
setCon.next();
}
else{
break;
}
}
Account ResellerAct;
Account DistributorAct;
Opportunity Oppt;
for(Asset Act : selectedAssets)
{
Temp_Assets__c TempAsset = new Temp_Assets__c();
TempAsset.Name = 'Sudhir';
TempAsset.AccountId__c = Act.AccountId;
TempAsset.Product__c = Act.Product2Id;
//Added by Unnat
TempAsset.Product_lookup__c= Act.Product2Id;
TempAsset.Serial_Number__c = Act.SerialNumber;
TempAsset.Last_Contract_Number__c = Act.last_contract_number__c;
TempAsset.Service_Start_Date__c = Act.Service_Start_Date_Min__c;
//TempAsset.Service_End_Date__c = Act.Service_End_Date_Max__c;
/***************Added by Unnat********************************************/
if (Act.Service_End_Date_Max__c != null) {
TempAsset.Service_End_Date__c = Act.Service_End_Date_Max__c;
}
else {
TempAsset.Service_End_Date__c = Act.InstallDate;
}
TempAsset.Install_Date__c = Act.InstallDate;
If (GetReseller.AccountId <> NULL)
{
ResellerAct = [ SELECT Id FROM Account WHERE ID = :GetReseller.AccountId Limit 1];
TempAsset.Reseller__c = ResellerAct.Id;
}
If (GetDistributor.AccountId <> NULL )
{
DistributorAct = [ SELECT Id FROM Account WHERE ID = :GetDistributor.AccountId Limit 1];
TempAsset.Distributor__c = DistributorAct.Id;
}
If ( GetOpportunity.Opportunity__c <> NULL )
{
Oppt = [SELECT Id FROM Opportunity WHERE ID = :GetOpportunity.Opportunity__c Limit 1];
TempAsset.Existing_Opportunity__c = Oppt.Id;
}
TempAsset.Incumbent_Reseller__c = IncumbentReseller;
TempAsset.Education__c = Education;
//TempAsset.Expiry_Date__c = GetExpireDate.Expire_Date__c;
TempAsset.Expiry_Date__c= maxDate;
TempAsset.New_Opportunity__c = GetNewOpportunity.New_Opportunity__c;
TempAsset.Expiry_Term__c = ExpireTerms;
/* Insert Bundel Checkbox Value */
if (this.selectedContactIds2.contains(Act.Id)){
bundsprt=true;
}
else {
bundsprt=false;
}
TempAsset.Bundle_Support__c = bundsprt;
System.debug('== Bundle Value is: ' + bundsprt);
//Add the selected Assets to the List
TempAssetList.add(TempAsset);
}
Insert TempAssetList;
setCon.setpageNumber(currentPageNumber);
}
/*
* return whether previous page exists
*/
public Boolean getHasPrevious(){
return this.setCon.getHasPrevious();
}
/*
* return whether next page exists
*/
public Boolean getHasNext(){
return this.setCon.getHasNext();
}
/*
* return page number
*/
public Integer getPageNumber(){
return this.setCon.getPageNumber();
}
/*
* return total pages
*/
Public Integer getTotalPages(){
Decimal totalSize = this.setCon.getResultSize();
Decimal pageSize = this.setCon.getPageSize();
Decimal pages = totalSize/pageSize;
return (Integer)pages.round(System.RoundingMode.CEILING);
}
/*
* helper class that represents a row
*/
public with sharing class CCWRowItem{
public Asset tContact{get;set;}
public Boolean IsSelected{get;set;}
public Boolean BundelSelected{get;set;}
public CCWRowItem(Asset c){
this.tContact=c;
this.IsSelected=false;
this.BundelSelected=false;
}
}
}
Do you have any suggest Please
Thanks
Sudhir