-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
6Questions
-
10Replies
How can I increase my code coverage
I wrote the below test class and it only covered 45% of my code, it doesn;t cover the next and previouse page reference
Test Class
public class ListPaginationBase { public Integer listSize {get; set;} public Integer pageSize {get; set;} public Integer currentPageIndex {get; set;} public List<Object> fullList {get; set;} public void initializePagination(Integer listTotalSize, Integer singlePageSize) { fullList = new List<Object>(); listSize = listTotalSize; pageSize = singlePageSize; currentPageIndex = 0; } public void initializePagination(List<Object> objectList, Integer singlePageSize) { fullList = ObjectList; listSize = fullList.size(); pageSize = singlePageSize; currentPageIndex = 0; } public Integer getPageCount() { //Returns the number of pages required to show all data given a page limit //if page limit is not set or is equal to zero, then return 1; dont divide by zero //is empty list then return 1 if (pageSize <= 0 || listSize <= 0) return 1; else return (Integer) Math.ceil((Decimal)listSize / (Decimal)pageSize); } public Boolean getHasNext() { //Returns true if the list has next pages return currentPageIndex < (getPageCount() - 1); } public Boolean getHasPrevious() { //Returns true if the list has previous pages return currentPageIndex > 0; } public Integer getfirstRowIndex() { //Returns the index of the first row to show in the PageBlockTable using the first attribute return currentPageIndex * pageSize; } public List<Object> getObjectPageList() { List<Object> returnList = new List<Object>(); for(Integer index = getFirstRowIndex(); index < getFirstRowIndex() + pageSize; index++) { if (index < fullList.size()) { returnList.add(fullList.get(index)); } } return returnList; } public PageReference firstAction() { //Action fired when the user click the First Button //Set the Page Index to Zero if(getHasPrevious()) currentPageIndex = 0; return null; } public PageReference lastAction() { //Action fired when the user click the Last Button //Set the Page Index to pages count - 1 if(getHasNext()) currentPageIndex = getPageCount() - 1; return null; } public PageReference nextAction() { //Action fired when the user click the Next Button //increment the current page index by 1 if(getHasNext()) currentPageIndex++; return null; } public PageReference previousAction() { //Action fired when the user click the Last Button //decrement the current page index by 1 if(getHasPrevious()) currentPageIndex--; return null; } }
Test Class
@isTest (SeeAllData=true) private class TESTAccountOpportunityTabExtension { static testmethod void AccountOpportunityTabExtension_Test (){ test.StartTest(); Account acc = new Account(Name ='icrm testing acc'); insert acc; opportunity opp = new opportunity ( Name='testing DIE 4/6/2015' , AccountId= acc.Id,StageName = 'Prospecting', type= 'parts', Description= 'describe', Inconterms__c = 'FCA', CloseDate = System.today().addDays(30)); insert opp; opportunity opps = new opportunity ( id = '0068E0000060EhbQAE', Name='testing DIE 4/6/2015' , AccountId= acc.Id,StageName = 'Prospecting', type= 'Sales', Opportunity_Division__c = 'PRODUCT SUPPORT', Description= 'describe', Inconterms__c = 'FCA', CloseDate = System.today().addDays(30)); update opps; opportunity Deltaopp = new opportunity ( id = '0068E000009BCivQAG', Name='testing DIE 4/6/2015' , AccountId= acc.Id,StageName = 'Prospecting', type= 'Sales', Opportunity_Division__c = 'POWER SYSTEM-DELTA(PERKINS)', Description= 'describe', Inconterms__c = 'FCA', CloseDate = System.today().addDays(30)); update Deltaopp; opportunity EnginePowerGenerationaopp = new opportunity ( id = '0068E000008Myy4QAC', Name='testing DIE 4/6/2015' , AccountId= acc.Id,StageName = 'Prospecting', type= 'Sales', Opportunity_Division__c = 'ENGINE POWER GENERATION', Description= 'describe', Inconterms__c = 'FCA', CloseDate = System.today().addDays(30)); update EnginePowerGenerationaopp ; opportunity Otheropp = new opportunity ( id = '0068E000009BDvgQAG', Name='testing DIE 4/6/2015' , AccountId= acc.Id,StageName = 'Prospecting', type= 'Sales', Opportunity_Division__c = 'OTHERS MISC - INTERNAL', Description= 'describe', Inconterms__c = 'FCA', CloseDate = System.today().addDays(30)); update Otheropp ; PageReference pref = Page.Opp_Tabs; pref.getParameters().put('id', acc.id); Test.setCurrentPage(pref); ApexPages.StandardController sc = new ApexPages.StandardController(acc); AccountOpportunityTabExtension mc = new AccountOpportunityTabExtension(sc); PageReference result = mc.NewOpp(); System.assertNotEquals(null, result); PageReference result2 = mc.sortConstructionPaginationList(); System.assertNotEquals(null, result); PageReference result3 = mc.sortProductSupportPaginationList(); System.assertNotEquals(null, result); PageReference result4 = mc.sortPowerSystemPaginationList(); System.assertNotEquals(null, result); PageReference result5 = mc.sortDeltaPaginationList(); System.assertNotEquals(null, result); PageReference result6 = mc.sortOtherPaginationList(); System.assertNotEquals(null, result); //ListPaginationBase code Coverage Integer currentPageIndex; ListPaginationBase p =new ListPaginationBase(); p.listSize = 7; currentPageIndex = 2; Boolean test1 = p.getHasNext(); Boolean test2 = p.getHasprevious(); Integer test3 = p.getPageCount(); Integer test4 = p.getfirstRowIndex(); PageReference result10 = p.previousAction(); System.assertNotEquals(null, result); PageReference result7 = p.firstAction(); System.assertNotEquals(null, result); PageReference result8 = p.lastAction(); System.assertNotEquals(null, result); PageReference result9 = p.nextAction(); System.assertNotEquals(null, result); p.getObjectPageList(); p.getPageCount(); p.PreviousAction(); p.NextAction(); p.firstAction(); p.LastAction(); p.getHasPrevious(); p.getHasNext(); p.getfirstRowIndex(); test.stopTest(); } public static testMethod void initializePagination() { Account acc = new Account(id = '0018E00000By5vZ', Name ='icrm testing acc'); update acc; opportunity opp = new opportunity ( Name='testing DIE 4/6/2015' , AccountId= acc.Id,StageName = 'Prospecting', type= 'parts', Description= 'describe', Inconterms__c = 'FCA', CloseDate = System.today().addDays(30)); insert opp; PageReference pageRef = Page.Opp_Tabs; Test.setCurrentPage(pageRef); ApexPages.StandardController sc = new ApexPages.StandardController(acc); AccountOpportunityTabExtension mc = new AccountOpportunityTabExtension(sc); ListPaginationBase p=new ListPaginationBase(); PageReference result = mc.NewOpp(); System.assertNotEquals(null, result); PageReference result7 = p.firstAction(); System.assertNotEquals(null, result); PageReference result8 = p.lastAction(); System.assertNotEquals(null, result); PageReference result9 = p.nextAction(); System.assertNotEquals(null, result); PageReference result10 = p.previousAction(); System.assertNotEquals(null, result); p.NextAction(); p.firstAction(); p.LastAction(); p.PreviousAction(); p.getHasPrevious(); p.getHasNext(); p.getfirstRowIndex(); p.getObjectPageList(); p.listSize = 7; } }
- reem sharawy
- November 20, 2016
- Like
- 0
how to cover page reference in test class
my apex class for pagination is only covered by 19%
Test Class
public class ListPaginationBase { public Integer listSize {get; set;} public Integer pageSize {get; set;} public Integer currentPageIndex {get; set;} public List<Object> fullList {get; set;} public void initializePagination(Integer listTotalSize, Integer singlePageSize) { fullList = new List<Object>(); listSize = listTotalSize; pageSize = singlePageSize; currentPageIndex = 0; } public void initializePagination(List<Object> objectList, Integer singlePageSize) { fullList = ObjectList; listSize = fullList.size(); pageSize = singlePageSize; currentPageIndex = 0; } public Integer getPageCount() { //Returns the number of pages required to show all data given a page limit //if page limit is not set or is equal to zero, then return 1; dont divide by zero //is empty list then return 1 if (pageSize <= 0 || listSize <= 0) return 1; else return (Integer) Math.ceil((Decimal)listSize / (Decimal)pageSize); } public Boolean getHasNext() { //Returns true if the list has next pages return currentPageIndex < (getPageCount() - 1); } public Boolean getHasPrevious() { //Returns true if the list has previous pages return currentPageIndex > 0; } public Integer getfirstRowIndex() { //Returns the index of the first row to show in the PageBlockTable using the first attribute return currentPageIndex * pageSize; } public List<Object> getObjectPageList() { List<Object> returnList = new List<Object>(); for(Integer index = getFirstRowIndex(); index < getFirstRowIndex() + pageSize; index++) { if (index < fullList.size()) { returnList.add(fullList.get(index)); } } return returnList; } public PageReference firstAction() { //Action fired when the user click the First Button //Set the Page Index to Zero if(getHasPrevious()) currentPageIndex = 0; return null; } public PageReference lastAction() { //Action fired when the user click the Last Button //Set the Page Index to pages count - 1 if(getHasNext()) currentPageIndex = getPageCount() - 1; return null; } public PageReference nextAction() { //Action fired when the user click the Next Button //increment the current page index by 1 if(getHasNext()) currentPageIndex++; return null; } public PageReference previousAction() { //Action fired when the user click the Last Button //decrement the current page index by 1 if(getHasPrevious()) currentPageIndex--; return null; } }
Test Class
@isTest (SeeAllData=true) private class TESTAccountOpportunityTabExtension { static testmethod void AccountOpportunityTabExtension_Test (){ test.StartTest(); Account acc = new Account(Name ='icrm testing acc'); insert acc; opportunity opp = new opportunity ( Name='testing DIE 4/6/2015' , AccountId= acc.Id,StageName = 'Prospecting', type= 'parts', Description= 'describe', Inconterms__c = 'FCA', CloseDate = System.today().addDays(30)); insert opp; opportunity opps = new opportunity ( id = '0068E0000060EhbQAE', Name='testing DIE 4/6/2015' , AccountId= acc.Id,StageName = 'Prospecting', type= 'Sales', Opportunity_Division__c = 'PRODUCT SUPPORT', Description= 'describe', Inconterms__c = 'FCA', CloseDate = System.today().addDays(30)); update opps; opportunity Deltaopp = new opportunity ( id = '0068E000009BCivQAG', Name='testing DIE 4/6/2015' , AccountId= acc.Id,StageName = 'Prospecting', type= 'Sales', Opportunity_Division__c = 'POWER SYSTEM-DELTA(PERKINS)', Description= 'describe', Inconterms__c = 'FCA', CloseDate = System.today().addDays(30)); update Deltaopp; opportunity EnginePowerGenerationaopp = new opportunity ( id = '0068E000008Myy4QAC', Name='testing DIE 4/6/2015' , AccountId= acc.Id,StageName = 'Prospecting', type= 'Sales', Opportunity_Division__c = 'ENGINE POWER GENERATION', Description= 'describe', Inconterms__c = 'FCA', CloseDate = System.today().addDays(30)); update EnginePowerGenerationaopp ; opportunity Otheropp = new opportunity ( id = '0068E000009BDvgQAG', Name='testing DIE 4/6/2015' , AccountId= acc.Id,StageName = 'Prospecting', type= 'Sales', Opportunity_Division__c = 'OTHERS MISC - INTERNAL', Description= 'describe', Inconterms__c = 'FCA', CloseDate = System.today().addDays(30)); update Otheropp ; PageReference pref = Page.Opp_Tabs; pref.getParameters().put('id', acc.id); Test.setCurrentPage(pref); ApexPages.StandardController sc = new ApexPages.StandardController(acc); AccountOpportunityTabExtension mc = new AccountOpportunityTabExtension(sc); PageReference result = mc.NewOpp(); System.assertNotEquals(null, result); PageReference result2 = mc.sortConstructionPaginationList(); System.assertNotEquals(null, result); PageReference result3 = mc.sortProductSupportPaginationList(); System.assertNotEquals(null, result); PageReference result4 = mc.sortPowerSystemPaginationList(); System.assertNotEquals(null, result); PageReference result5 = mc.sortDeltaPaginationList(); System.assertNotEquals(null, result); PageReference result6 = mc.sortOtherPaginationList(); System.assertNotEquals(null, result); test.stopTest(); } }
- reem sharawy
- November 15, 2016
- Like
- 0
page reference in test class
Hello
I can't have trouble covering my page reference in test class
test class
I can't have trouble covering my page reference in test class
public class AccountInvoiceTabExtension { public ListPaginationBase ConstructionPaginationBaseObject {get; set;} public ListPaginationBase DeltaPaginationBaseObject {get; set;} public ListPaginationBase EnginePowerGenerationPaginationBaseObject {get; set;} public ListPaginationBase MiningPaginationBaseObject {get; set;} public ListPaginationBase ProductSupportPaginationBaseObject {get; set;} public ListPaginationBase SamsungPaginationBaseObject {get; set;} public ListPaginationBase OtherPaginationBaseObject {get; set;} public List<InvoiceWrapper> ConstructionInvoiceList {get; set;} public List<InvoiceWrapper> DeltaInvoiceList {get; set;} public List<InvoiceWrapper> EnginePowerGenerationInvoiceList {get; set;} public List<InvoiceWrapper> MiningInvoiceList {get; set;} public List<InvoiceWrapper> ProductSupportInvoiceList {get; set;} public List<InvoiceWrapper> SamsungInvoiceList {get; set;} public List<InvoiceWrapper> OtherInvoiceList {get; set;} public String constructionInvoiceSort {get; set;} public boolean constructionInvoiceSortDesc {get; set;} public String DeltaInvoiceSort {get; set;} public boolean DeltaInvoiceSortDesc {get; set;} public String EnginePowerGenerationInvoiceSort {get; set;} public boolean EnginePowerGenerationInvoiceSortDesc {get; set;} public String MiningInvoiceSort {get; set;} public boolean MiningInvoiceSortDesc {get; set;} public String ProductSupportInvoiceSort {get; set;} public boolean ProductSupportInvoiceSortDesc {get; set;} public String SamsungInvoiceSort {get; set;} public boolean SamsungInvoiceSortDesc {get; set;} public String OtherInvoiceSort {get; set;} public boolean OtherInvoiceSortDesc {get; set;} public Account currentAccount {get; set;} public AccountInvoiceTabExtension(ApexPages.StandardController controller) { currentAccount = (Account) controller.getRecord(); constructionInvoiceSort = 'Name'; constructionInvoiceSortDesc = false; DeltaInvoiceSort = 'Name'; DeltaInvoiceSortDesc = false; EnginePowerGenerationInvoiceSort = 'Name'; EnginePowerGenerationInvoiceSortDesc = false; MiningInvoiceSort = 'Name'; MiningInvoiceSortDesc = false; ProductSupportInvoiceSort = 'Name'; ProductSupportInvoiceSortDesc = false; SamsungInvoiceSort = 'Name'; SamsungInvoiceSortDesc = false; OtherInvoiceSort = 'Name'; OtherInvoiceSortDesc = false; refreshConstructionInvoiceList(); refreshDeltaInvoiceList (); refreshEnginePowerGenerationInvoiceList(); refreshMiningPaginationList(); refreshProductSupportInvoiceList(); refreshSamsungInvoiceList(); refreshOtherInvoiceList(); } public PageReference sortConstructionPaginationList() { refreshConstructionInvoiceList(); return null; } public PageReference sortDeltaPaginationList() { refreshDeltaInvoiceList(); return null; } public PageReference sortEnginePowerGenerationPaginationList() { refreshEnginePowerGenerationInvoiceList(); return null; } public PageReference sortMiningPaginationList() { refreshMiningPaginationList(); return null; } public PageReference sortProductSupportPaginationList() { refreshProductSupportInvoiceList(); return null; } public PageReference sortSamsungPaginationList() { refreshSamsungInvoiceList(); return null; } public PageReference sortOtherPaginationList() { refreshOtherInvoiceList(); return null; } private void refreshConstructionInvoiceList() { getConstructionInvoiceList(); constructionPaginationBaseObject = new ListPaginationBase(); constructionPaginationBaseObject.initializePagination(ConstructionInvoiceList, 20); } private void refreshDeltaInvoiceList() { getDeltaInvoiceList(); DeltaPaginationBaseObject = new ListPaginationBase(); DeltaPaginationBaseObject.initializePagination(DeltaInvoiceList, 20); } private void refreshEnginePowerGenerationInvoiceList() { getEnginePowerGenerationInvoiceList(); EnginePowerGenerationPaginationBaseObject = new ListPaginationBase(); EnginePowerGenerationPaginationBaseObject.initializePagination(EnginePowerGenerationInvoiceList, 20); } private void refreshMiningPaginationList() { getMiningInvoiceList(); MiningPaginationBaseObject = new ListPaginationBase(); MiningPaginationBaseObject.initializePagination(MiningInvoiceList, 20); } private void refreshProductSupportInvoiceList() { getProductSupportInvoiceList (); ProductSupportPaginationBaseObject = new ListPaginationBase(); ProductSupportPaginationBaseObject.initializePagination(ProductSupportInvoiceList, 20); } private void refreshSamsungInvoiceList() { getSamsungInvoiceList(); SamsungPaginationBaseObject = new ListPaginationBase(); SamsungPaginationBaseObject.initializePagination(SamsungInvoiceList, 20); } private void refreshOtherInvoiceList() { getOtherInvoiceList(); OtherPaginationBaseObject = new ListPaginationBase(); OtherPaginationBaseObject.initializePagination(OtherInvoiceList, 20); } public class InvoiceWrapper { public Id InvoiceId {get; set;} public String orderNumber {get; set;} public Date InvoiceDate {get; set;} public String OrderType {get; set;} public String ModelDescription {get; set;} public String InvoiceType {get; set;} public String OrderTaking {get; set;} public double TotalSellVAT {get; set;} public String CostCenter {get; set;} public String CostCenterDivision {get; set;} public Id ordertakingid {get; set;} } private void getConstructionInvoiceList() { ConstructionInvoiceList = new List<InvoiceWrapper>(); String soqlQuery = 'SELECT Id, Name, Cost_Centre_Main_Division__c, Cost_Center_Division__c, Invoice_Date__c, Order_Type__c, Model_Description__c, Invoice_Type__c, Order_Taking__r.name, Order_Taking__r.id, Total_Price_Net__c, Cost_Center__c'; soqlQuery += ' FROM Order_ManPro__c '; soqlQuery += ' WHERE Account_order__c = \'' + currentAccount.Id + '\''; soqlQuery += ' AND Cost_Centre_Main_Division__c = \'CONSTRUCTION ALL\''; soqlQuery += ' ORDER BY ' + constructionInvoiceSort; if (constructionInvoiceSortDesc) soqlQuery += ' DESC'; for (Order_ManPro__c constInvoice : Database.query(soqlQuery)) { InvoiceWrapper wrapper = new InvoiceWrapper(); wrapper.InvoiceId = constInvoice.Id; wrapper.orderNumber = constInvoice.Name; wrapper.InvoiceDate = constInvoice.Invoice_Date__c; wrapper.OrderType = constInvoice.Order_Type__c; wrapper.ModelDescription = constInvoice.Model_Description__c; wrapper.InvoiceType = constInvoice.Invoice_Type__c; wrapper.OrderTaking = constInvoice.Order_Taking__r.name; wrapper.ordertakingid = constInvoice.Order_Taking__r.id; wrapper.TotalSellVAT = constInvoice.Total_Price_Net__c; wrapper.CostCenter = constInvoice.Cost_Center__c; wrapper.CostCenterDivision = constInvoice.Cost_Center_Division__c; ConstructionInvoiceList.add(wrapper); } } private void getDeltaInvoiceList() { DeltaInvoiceList = new List<InvoiceWrapper>(); String soqlQuery = 'SELECT Id, Name, Cost_Centre_Main_Division__c, Account_order__c, Cost_Center_Division__c, Invoice_Date__c, Order_Type__c, Model_Description__c, Invoice_Type__c, Order_Taking__r.name, Total_Price_Net__c, Cost_Center__c'; soqlQuery += ' FROM Order_ManPro__c '; soqlQuery += ' WHERE Account_order__c = \'' + currentAccount.Id + '\''; soqlQuery += ' AND Cost_Centre_Main_Division__c = \'DELTA\''; soqlQuery += ' ORDER BY ' + DeltaInvoiceSort; if (DeltaInvoiceSortDesc) soqlQuery += ' DESC'; for (Order_ManPro__c DeltaInvoice : Database.query(soqlQuery)) { InvoiceWrapper wrapper = new InvoiceWrapper(); wrapper.InvoiceId = DeltaInvoice.Id; wrapper.orderNumber = DeltaInvoice.Name; wrapper.InvoiceDate = DeltaInvoice.Invoice_Date__c; wrapper.OrderType = DeltaInvoice.Order_Type__c; wrapper.ModelDescription = DeltaInvoice.Model_Description__c; wrapper.InvoiceType = DeltaInvoice.Invoice_Type__c; wrapper.OrderTaking = DeltaInvoice.Order_Taking__r.name; wrapper.ordertakingid = DeltaInvoice.Order_Taking__r.id; wrapper.TotalSellVAT = DeltaInvoice.Total_Price_Net__c; wrapper.CostCenter = DeltaInvoice.Cost_Center__c; wrapper.CostCenterDivision = DeltaInvoice.Cost_Center_Division__c; DeltaInvoiceList.add(wrapper); } } private void getEnginePowerGenerationInvoiceList() { EnginePowerGenerationInvoiceList = new List<InvoiceWrapper>(); String soqlQuery = 'SELECT Id, Name, Cost_Centre_Main_Division__c, Account_order__c, Cost_Center_Division__c, Invoice_Date__c, Order_Type__c, Model_Description__c, Invoice_Type__c, Order_Taking__r.name, Total_Price_Net__c, Cost_Center__c'; soqlQuery += ' FROM Order_ManPro__c '; soqlQuery += ' WHERE Account_order__c = \'' + currentAccount.Id + '\''; soqlQuery += ' AND Cost_Centre_Main_Division__c = \'ENGINE POWER GENERATION\''; soqlQuery += ' ORDER BY ' + EnginePowerGenerationInvoiceSort; if (EnginePowerGenerationInvoiceSortDesc) soqlQuery += ' DESC'; for (Order_ManPro__c EnginePowerGenerationInvoice : Database.query(soqlQuery)) { InvoiceWrapper wrapper = new InvoiceWrapper(); wrapper.InvoiceId = EnginePowerGenerationInvoice.Id; wrapper.orderNumber = EnginePowerGenerationInvoice.Name; wrapper.InvoiceDate = EnginePowerGenerationInvoice.Invoice_Date__c; wrapper.OrderType = EnginePowerGenerationInvoice.Order_Type__c; wrapper.ModelDescription = EnginePowerGenerationInvoice.Model_Description__c; wrapper.InvoiceType = EnginePowerGenerationInvoice.Invoice_Type__c; wrapper.OrderTaking = EnginePowerGenerationInvoice.Order_Taking__r.name; wrapper.ordertakingid = EnginePowerGenerationInvoice.Order_Taking__r.id; wrapper.TotalSellVAT = EnginePowerGenerationInvoice.Total_Price_Net__c; wrapper.CostCenter = EnginePowerGenerationInvoice.Cost_Center__c; wrapper.CostCenterDivision = EnginePowerGenerationInvoice.Cost_Center_Division__c; EnginePowerGenerationInvoiceList.add(wrapper); } } private void getMiningInvoiceList() { MiningInvoiceList = new List<InvoiceWrapper>(); String soqlQuery = 'SELECT Id, Name, Cost_Centre_Main_Division__c, Account_order__c, Cost_Center_Division__c, Invoice_Date__c, Order_Type__c, Model_Description__c, Invoice_Type__c, Order_Taking__r.name, Total_Price_Net__c, Cost_Center__c'; soqlQuery += ' FROM Order_ManPro__c '; soqlQuery += ' WHERE Account_order__c = \'' + currentAccount.Id + '\''; soqlQuery += ' AND Cost_Centre_Main_Division__c = \'MINING\''; soqlQuery += ' ORDER BY ' + MiningInvoiceSort; if (MiningInvoiceSortDesc) soqlQuery += ' DESC'; for (Order_ManPro__c MiningInvoice : Database.query(soqlQuery)) { InvoiceWrapper wrapper = new InvoiceWrapper(); wrapper.InvoiceId = MiningInvoice.Id; wrapper.orderNumber = MiningInvoice.Name; wrapper.InvoiceDate = MiningInvoice.Invoice_Date__c; wrapper.OrderType = MiningInvoice.Order_Type__c; wrapper.ModelDescription = MiningInvoice.Model_Description__c; wrapper.InvoiceType = MiningInvoice.Invoice_Type__c; wrapper.OrderTaking = MiningInvoice.Order_Taking__r.name; wrapper.ordertakingid = MiningInvoice.Order_Taking__r.id; wrapper.TotalSellVAT = MiningInvoice.Total_Price_Net__c; wrapper.CostCenter = MiningInvoice.Cost_Center__c; wrapper.CostCenterDivision = MiningInvoice.Cost_Center_Division__c; MiningInvoiceList.add(wrapper); } } private void getProductSupportInvoiceList() { ProductSupportInvoiceList = new List<InvoiceWrapper>(); String soqlQuery = 'SELECT Id, Name, Cost_Centre_Main_Division__c, Account_order__c, Cost_Center_Division__c, Invoice_Date__c, Order_Type__c, Model_Description__c, Invoice_Type__c, Order_Taking__r.name, Total_Price_Net__c, Cost_Center__c'; soqlQuery += ' FROM Order_ManPro__c '; soqlQuery += ' WHERE Account_order__c = \'' + currentAccount.Id + '\''; soqlQuery += ' AND Cost_Centre_Main_Division__c = \'PRODUCT SUPPORT\''; soqlQuery += ' ORDER BY ' + ProductSupportInvoiceSort; if (ProductSupportInvoiceSortDesc) soqlQuery += ' DESC'; for (Order_ManPro__c ProductSupportInvoice : Database.query(soqlQuery)) { InvoiceWrapper wrapper = new InvoiceWrapper(); wrapper.InvoiceId = ProductSupportInvoice.Id; wrapper.orderNumber = ProductSupportInvoice.Name; wrapper.InvoiceDate = ProductSupportInvoice.Invoice_Date__c; wrapper.OrderType = ProductSupportInvoice.Order_Type__c; wrapper.ModelDescription = ProductSupportInvoice.Model_Description__c; wrapper.InvoiceType = ProductSupportInvoice.Invoice_Type__c; wrapper.OrderTaking = ProductSupportInvoice.Order_Taking__r.name; wrapper.ordertakingid = ProductSupportInvoice.Order_Taking__r.id; wrapper.TotalSellVAT = ProductSupportInvoice.Total_Price_Net__c; wrapper.CostCenter = ProductSupportInvoice.Cost_Center__c; wrapper.CostCenterDivision = ProductSupportInvoice.Cost_Center_Division__c; ProductSupportInvoiceList.add(wrapper); } } private void getSamsungInvoiceList() { SamsungInvoiceList = new List<InvoiceWrapper>(); String soqlQuery = 'SELECT Id, Name, Cost_Centre_Main_Division__c, Account_order__c, Cost_Center_Division__c, Invoice_Date__c, Order_Type__c, Model_Description__c, Invoice_Type__c, Order_Taking__r.name, Total_Price_Net__c, Cost_Center__c'; soqlQuery += ' FROM Order_ManPro__c '; soqlQuery += ' WHERE Account_order__c = \'' + currentAccount.Id + '\''; soqlQuery += ' AND Cost_Centre_Main_Division__c = \'SAMSUNG\''; soqlQuery += ' ORDER BY ' + SamsungInvoiceSort; if (SamsungInvoiceSortDesc) soqlQuery += ' DESC'; for (Order_ManPro__c SamsungInvoice : Database.query(soqlQuery)) { InvoiceWrapper wrapper = new InvoiceWrapper(); wrapper.InvoiceId = SamsungInvoice .Id; wrapper.orderNumber = SamsungInvoice .Name; wrapper.InvoiceDate = SamsungInvoice .Invoice_Date__c; wrapper.OrderType = SamsungInvoice .Order_Type__c; wrapper.ModelDescription = SamsungInvoice .Model_Description__c; wrapper.InvoiceType = SamsungInvoice.Invoice_Type__c; wrapper.OrderTaking = SamsungInvoice.Order_Taking__r.name; wrapper.ordertakingid = SamsungInvoice.Order_Taking__r.id; wrapper.TotalSellVAT = SamsungInvoice.Total_Price_Net__c; wrapper.CostCenter = SamsungInvoice.Cost_Center__c; wrapper.CostCenterDivision = SamsungInvoice.Cost_Center_Division__c; SamsungInvoiceList.add(wrapper); } } private void getOtherInvoiceList() { OtherInvoiceList = new List<InvoiceWrapper>(); String soqlQuery = 'SELECT Id, Name, Cost_Centre_Main_Division__c, Account_order__c, Cost_Center_Division__c, Invoice_Date__c, Order_Type__c, Model_Description__c, Invoice_Type__c, Order_Taking__r.name, Total_Price_Net__c, Cost_Center__c'; soqlQuery += ' FROM Order_ManPro__c '; soqlQuery += ' WHERE Account_order__c = \'' + currentAccount.Id + '\''; soqlQuery += ' AND Cost_Centre_Main_Division__c = \'OTHERS MISC - INTERNAL\''; soqlQuery += ' ORDER BY ' + OtherInvoiceSort; if (OtherInvoiceSortDesc) soqlQuery += ' DESC'; for (Order_ManPro__c OtherInvoice : Database.query(soqlQuery)) { InvoiceWrapper wrapper = new InvoiceWrapper(); wrapper.InvoiceId = OtherInvoice.Id; wrapper.orderNumber = OtherInvoice.Name; wrapper.InvoiceDate = OtherInvoice.Invoice_Date__c; wrapper.OrderType = OtherInvoice.Order_Type__c; wrapper.ModelDescription = OtherInvoice.Model_Description__c; wrapper.InvoiceType = OtherInvoice.Invoice_Type__c; wrapper.OrderTaking = OtherInvoice.Order_Taking__r.name; wrapper.ordertakingid = OtherInvoice.Order_Taking__r.id; wrapper.TotalSellVAT = OtherInvoice.Total_Price_Net__c; wrapper.CostCenter = OtherInvoice.Cost_Center__c; wrapper.CostCenterDivision = OtherInvoice.Cost_Center_Division__c; OtherInvoiceList.add(wrapper); } } public pageReference NewInvoice() { PageReference pageRef = new PageReference('/a0J/e?CF00Nb0000005YEDS_lkid=' + currentAccount.Id + '&CF00Nb0000005YEDS=' + currentAccount.Name); pageRef.setRedirect(true); return pageRef; } }
test class
@isTest (SeeAllData=true) private class TESTAccountInvoiceTabExtension { static testmethod void AccountInvoiceTabExtension_Test (){ test.StartTest(); Account acc = new Account(Name ='icrm testing acc'); insert acc; Order_ManPro__c constInvoice = new Order_ManPro__c ( Name='1234', Account_order__c= acc.Id, Cost_Centre_Main_Division__c ='CONSTRUCTION ALL', Cost_Center_ManPRO__c = 'a0e8E000001OZuM', Cost_Center_Division__c = 'CONSTRUCTION ALL',Cost_Centre_Description__c = 'Machine Rental (Const)',Cost_Center__c = 'CMM', CurrencyIsoCode = 'USD', Invoice_Date__c = System.today().addDays(30),Order_Type__c = 'rergg', Model_Description__c = 'desc', Order_Taking__c = '005b00000010h3o', External_Order_ID__c = '9876000'); insert constInvoice; Order_ManPro__c DeltaInvoice = new Order_ManPro__c ( Name='234' , Account_order__c= acc.Id, Cost_Centre_Main_Division__c ='DELTA', Cost_Center_ManPRO__c = 'a0e8E000001OZuM', Cost_Center_Division__c = 'AGRICULTURE',Cost_Centre_Description__c = 'John Deer',Cost_Center__c = 'NMB', CurrencyIsoCode = 'USD', Invoice_Date__c = System.today().addDays(30),Order_Type__c = 'rergg', Model_Description__c = 'desc', Order_Taking__c = '005b00000010h3o', External_Order_ID__c = '98760900'); insert DeltaInvoice; Order_ManPro__c EnginePowerGenerationInvoice = new Order_ManPro__c (Name='234' , Account_order__c= acc.Id, Cost_Centre_Main_Division__c ='ENGINE POWER GENERATION', Cost_Center_ManPRO__c = 'a0e8E000001OZvj', Cost_Center_Division__c = 'MARINE',Cost_Centre_Description__c = 'Marine Engines',Cost_Center__c = 'CEC', CurrencyIsoCode = 'USD', Invoice_Date__c = System.today().addDays(30),Order_Type__c = 'rergg', Model_Description__c = 'desc', Order_Taking__c = '005b00000010h3o', External_Order_ID__c = '1'); insert EnginePowerGenerationInvoice; Order_ManPro__c MiningInvoice = new Order_ManPro__c (Name='234' , Account_order__c= acc.Id, Cost_Centre_Main_Division__c ='MINING', Cost_Center_ManPRO__c = 'a0e8E000001OZw8', Cost_Center_Division__c = 'MINING',Cost_Centre_Description__c = 'Rental machines Mining',Cost_Center__c = 'CMI', CurrencyIsoCode = 'USD', Invoice_Date__c = System.today().addDays(30),Order_Type__c = 'rergg', Model_Description__c = 'desc', Order_Taking__c = '005b00000010h3o', External_Order_ID__c = '9'); insert MiningInvoice; Order_ManPro__c ProductSupportInvoice = new Order_ManPro__c (Name='234' , Account_order__c= acc.Id, Cost_Centre_Main_Division__c ='PRODUCT SUPPORT', Cost_Center_ManPRO__c = 'a0e8E000001OZvV', Cost_Center_Division__c = 'PRODUCT SUPPORT',Cost_Centre_Description__c = 'Service Admin Mining',Cost_Center__c = 'CS2', CurrencyIsoCode = 'USD', Invoice_Date__c = System.today().addDays(30),Order_Type__c = 'rergg', Model_Description__c = 'desc', Order_Taking__c = '005b00000010h3o', External_Order_ID__c = '2'); insert ProductSupportInvoice; Order_ManPro__c SamsungInvoice = new Order_ManPro__c (Name='234' , Account_order__c= acc.Id, Cost_Centre_Main_Division__c ='SAMSUNG', Cost_Center_ManPRO__c = 'a0e8E000001OZxo', Cost_Center_Division__c = 'SAMSUNG',Cost_Centre_Description__c = 'Audio and Video Products',Cost_Center__c = 'TEC', CurrencyIsoCode = 'USD', Invoice_Date__c = System.today().addDays(30),Order_Type__c = 'rergg', Model_Description__c = 'desc', Order_Taking__c = '005b00000010h3o', External_Order_ID__c = '4'); insert SamsungInvoice; Order_ManPro__c OtherInvoice = new Order_ManPro__c (Name='234' , Account_order__c= acc.Id, Cost_Centre_Main_Division__c ='OTHERS MISC - INTERNAL', Cost_Center_ManPRO__c = 'a0e8E000001OZuZ', Cost_Center_Division__c = 'OTHERS MISC - INTERNAL',Cost_Centre_Description__c = 'Internal Sales Reps',Cost_Center__c = 'ZSR', CurrencyIsoCode = 'USD', Invoice_Date__c = System.today().addDays(30),Order_Type__c = 'rergg', Model_Description__c = 'desc', Order_Taking__c = '005b00000010h3o', External_Order_ID__c = '6'); insert OtherInvoice; PageReference pref = Page.Invoice_Tabs; pref.getParameters().put('id', acc.id); Test.setCurrentPage(pref); ApexPages.StandardController sc = new ApexPages.StandardController(acc); AccountInvoiceTabExtension mc = new AccountInvoiceTabExtension(sc); PageReference result = AccountInvoiceTabExtension.autoRun(); System.assertNotEquals(null, result); test.stopTest(); } }
- reem sharawy
- November 14, 2016
- Like
- 0
Updating team member object on delete method
Hi All
I am trying to update my Team_Member__c object on delete method for account share to change account access for 'read/writte' to 'read' but it's not doing any action on my page
I am trying to update my Team_Member__c object on delete method for account share to change account access for 'read/writte' to 'read' but it's not doing any action on my page
//The Logic for the Delete the Account Team Member if(teamMemberDeleteMap.size() > 0) { List<AccountTeamMember> accountTeamMemberDeleteList = new List<AccountTeamMember>(); //Query to the List... List<AccountTeamMember> accountTeamMemberList = new List<AccountTeamMember>([Select UserId, TeamMemberRole, Id, AccountId, AccountAccessLevel From AccountTeamMember where AccountId IN : accountIdsSet]); List<AccountShare> AccountShareList = new List<AccountShare>([Select UserOrGroupId, AccountId, AccountAccessLevel From AccountShare where AccountId IN : accountIdsSet]); List<Team_Member__c> remainteammemberList = new List<Team_Member__c>([Select Team_Member__c , Account_Access__c, Account__c From Team_Member__c where Account__c IN : accountIdsSet]); for(AccountTeamMember teamMember : accountTeamMemberList) { //System.debug('The Account Team : '+ teamMember.AccountId+''+teamMember.UserId ); //For Update.... if(teamMemberDeleteMap.get(teamMember.AccountId+''+teamMember.UserId) != null) { accountTeamMemberDeleteList.add(teamMember); } } for(Team_Member__c teammemberObject : remainteammemberList ) { teammemberObject.Account_Access__c = 'Read'; } //Deleting the Records... if(accountTeamMemberDeleteList.size() > 0) upsert remainteammemberList ; delete accountTeamMemberDeleteList; }
- reem sharawy
- October 18, 2016
- Like
- 0
command button open new tab
Hello
I added a new button on my page to be able to create new opportunity from a visualforce page which replace the opportunity related leist on the account detailed page, the problem is that button doesn't open a new tab and opens in the exisiting Vf page
I added a new button on my page to be able to create new opportunity from a visualforce page which replace the opportunity related leist on the account detailed page, the problem is that button doesn't open a new tab and opens in the exisiting Vf page
<apex:page standardController="Account" extensions="AccountOpportunityTabExtension"> <html xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <apex:form style="height: 800px;"> <apex:tabPanel > <!-- Add Different Tabs Like the one below --> <apex:tab label="{!$Label.Construction_All_Opportunity}" style="overflow: auto; height: auto;"> <apex:pageBlock > <apex:commandButton value="New" action="/apex/Opp_layout_new_edit?oppId={!Account.id}"/> <!--<Apex:commandButton value="New" onclick="window.open=(/apex/Opp_layout_new_edit?oppId={!Account.id}','_blank')" /> --> <apex:pageBlockSection id="contructionSection" collapsible="false" columns="1"> <apex:pageBlockTable value="{!constructionPaginationBaseObject.objectPageList}" var="opportunity"> <!--<apex:commandButton> <apex:commandLink value="New" action="/apex/Opp_layout_new_edit?oppId={!opportunity['opportunityId']}" target="_blank"/> </apex:commandButton> --> <apex:column > <apex:outputLink title="" value="/{!opportunity['opportunityId']}/e?retURL=/apex/{!$CurrentPage.Name}" style="font-weight:bold" target="_blank">Edit</apex:outputLink> </apex:column> <apex:column headerValue="Opportunity Name"> <apex:commandLink action="/{!opportunity['opportunityId']}" value="{!opportunity['OpportunityName']}" target="_blank"/> </apex:column> <!--<apex:column headerValue="Purchase Type" value="{!opportunity['PurchaseType']}" />--> <apex:column headerValue="Stage" value="{!opportunity['StageName']}" /> <apex:column headerValue="Amount" value="{!opportunity['Amount']}" /> <apex:column headerValue="Order Date" > <apex:outputText value="{0,date,dd/MM/yyyy}"> <apex:param value="{!opportunity['CloseDate']}" /> </apex:outputText> </apex:column> <apex:column headerValue="Owner Full Name"> <apex:commandLink action="/{!opportunity['opportunityId']}" value="{!opportunity['Owner']}" target="_blank"/> </apex:column> </apex:pageBlockTable> <apex:outputPanel > <apex:commandButton value="|< First" action="{!constructionPaginationBaseObject.firstAction}" reRender="contructionSection" disabled="{!NOT(constructionPaginationBaseObject.hasPrevious)}" /> <apex:commandButton value="< Previous" action="{!constructionPaginationBaseObject.previousAction}" reRender="contructionSection" disabled="{!NOT(constructionPaginationBaseObject.hasPrevious)}" /> <apex:outputText value="Page {0} of {1}"> <apex:param value="{!constructionPaginationBaseObject.currentPageIndex + 1}"/> <!-- Adding 1 because this is zero indexed --> <apex:param value="{!constructionPaginationBaseObject.pageCount}"/> </apex:outputText> <apex:commandButton value="Next >" action="{!constructionPaginationBaseObject.nextAction}" reRender="contructionSection" disabled="{!NOT(constructionPaginationBaseObject.hasNext)}" /> <apex:commandButton value="Last >|" action="{!constructionPaginationBaseObject.lastAction}" reRender="contructionSection" disabled="{!NOT(constructionPaginationBaseObject.hasNext)}" /> </apex:outputPanel> </apex:pageBlockSection> </apex:pageBlock> </apex:tab> </apex:tabPanel> </apex:form> </html> </apex:page>
- reem sharawy
- October 18, 2016
- Like
- 0
related opportunities with pagination
hi
I am trying to create a vf page to fetch related opportunities for specific account and to add pagination.
Whenever I try to save my code I get the below error:
Error: Compile Error: Method does not exist or incorrect signature: [ListPaginationBase].initializePagination(List<NewStockTransferExtension.materialWrapperList>, Integer)
I am trying to create a vf page to fetch related opportunities for specific account and to add pagination.
Whenever I try to save my code I get the below error:
Error: Compile Error: Method does not exist or incorrect signature: [ListPaginationBase].initializePagination(List<NewStockTransferExtension.materialWrapperList>, Integer)
public class NewStockTransferExtension{ public ListPaginationBase ConstructionOpportunityList {get; set;} public list<materialWrapperList> materialWrapperList{get;set;} public Account currentAccount {get; set;} public NewStockTransferExtension(ApexPages.StandardController controller) { ConstructionOpportunityList = new ListPaginationBase(); currentAccount = (Account) controller.getRecord(); ConstructionOpportunityList.initializePagination(materialWrapperList, 20); } public class materialWrapperList { public boolean checked{get;set;} Public Opportunity ConstructionOpportunityList {get;set;} public materialWrapperList(Opportunity ConstructionOpportunityList ){ this.ConstructionOpportunityList = ConstructionOpportunityList ; } } }
- reem sharawy
- October 11, 2016
- Like
- 0
How can I increase my code coverage
I wrote the below test class and it only covered 45% of my code, it doesn;t cover the next and previouse page reference
Test Class
public class ListPaginationBase { public Integer listSize {get; set;} public Integer pageSize {get; set;} public Integer currentPageIndex {get; set;} public List<Object> fullList {get; set;} public void initializePagination(Integer listTotalSize, Integer singlePageSize) { fullList = new List<Object>(); listSize = listTotalSize; pageSize = singlePageSize; currentPageIndex = 0; } public void initializePagination(List<Object> objectList, Integer singlePageSize) { fullList = ObjectList; listSize = fullList.size(); pageSize = singlePageSize; currentPageIndex = 0; } public Integer getPageCount() { //Returns the number of pages required to show all data given a page limit //if page limit is not set or is equal to zero, then return 1; dont divide by zero //is empty list then return 1 if (pageSize <= 0 || listSize <= 0) return 1; else return (Integer) Math.ceil((Decimal)listSize / (Decimal)pageSize); } public Boolean getHasNext() { //Returns true if the list has next pages return currentPageIndex < (getPageCount() - 1); } public Boolean getHasPrevious() { //Returns true if the list has previous pages return currentPageIndex > 0; } public Integer getfirstRowIndex() { //Returns the index of the first row to show in the PageBlockTable using the first attribute return currentPageIndex * pageSize; } public List<Object> getObjectPageList() { List<Object> returnList = new List<Object>(); for(Integer index = getFirstRowIndex(); index < getFirstRowIndex() + pageSize; index++) { if (index < fullList.size()) { returnList.add(fullList.get(index)); } } return returnList; } public PageReference firstAction() { //Action fired when the user click the First Button //Set the Page Index to Zero if(getHasPrevious()) currentPageIndex = 0; return null; } public PageReference lastAction() { //Action fired when the user click the Last Button //Set the Page Index to pages count - 1 if(getHasNext()) currentPageIndex = getPageCount() - 1; return null; } public PageReference nextAction() { //Action fired when the user click the Next Button //increment the current page index by 1 if(getHasNext()) currentPageIndex++; return null; } public PageReference previousAction() { //Action fired when the user click the Last Button //decrement the current page index by 1 if(getHasPrevious()) currentPageIndex--; return null; } }
Test Class
@isTest (SeeAllData=true) private class TESTAccountOpportunityTabExtension { static testmethod void AccountOpportunityTabExtension_Test (){ test.StartTest(); Account acc = new Account(Name ='icrm testing acc'); insert acc; opportunity opp = new opportunity ( Name='testing DIE 4/6/2015' , AccountId= acc.Id,StageName = 'Prospecting', type= 'parts', Description= 'describe', Inconterms__c = 'FCA', CloseDate = System.today().addDays(30)); insert opp; opportunity opps = new opportunity ( id = '0068E0000060EhbQAE', Name='testing DIE 4/6/2015' , AccountId= acc.Id,StageName = 'Prospecting', type= 'Sales', Opportunity_Division__c = 'PRODUCT SUPPORT', Description= 'describe', Inconterms__c = 'FCA', CloseDate = System.today().addDays(30)); update opps; opportunity Deltaopp = new opportunity ( id = '0068E000009BCivQAG', Name='testing DIE 4/6/2015' , AccountId= acc.Id,StageName = 'Prospecting', type= 'Sales', Opportunity_Division__c = 'POWER SYSTEM-DELTA(PERKINS)', Description= 'describe', Inconterms__c = 'FCA', CloseDate = System.today().addDays(30)); update Deltaopp; opportunity EnginePowerGenerationaopp = new opportunity ( id = '0068E000008Myy4QAC', Name='testing DIE 4/6/2015' , AccountId= acc.Id,StageName = 'Prospecting', type= 'Sales', Opportunity_Division__c = 'ENGINE POWER GENERATION', Description= 'describe', Inconterms__c = 'FCA', CloseDate = System.today().addDays(30)); update EnginePowerGenerationaopp ; opportunity Otheropp = new opportunity ( id = '0068E000009BDvgQAG', Name='testing DIE 4/6/2015' , AccountId= acc.Id,StageName = 'Prospecting', type= 'Sales', Opportunity_Division__c = 'OTHERS MISC - INTERNAL', Description= 'describe', Inconterms__c = 'FCA', CloseDate = System.today().addDays(30)); update Otheropp ; PageReference pref = Page.Opp_Tabs; pref.getParameters().put('id', acc.id); Test.setCurrentPage(pref); ApexPages.StandardController sc = new ApexPages.StandardController(acc); AccountOpportunityTabExtension mc = new AccountOpportunityTabExtension(sc); PageReference result = mc.NewOpp(); System.assertNotEquals(null, result); PageReference result2 = mc.sortConstructionPaginationList(); System.assertNotEquals(null, result); PageReference result3 = mc.sortProductSupportPaginationList(); System.assertNotEquals(null, result); PageReference result4 = mc.sortPowerSystemPaginationList(); System.assertNotEquals(null, result); PageReference result5 = mc.sortDeltaPaginationList(); System.assertNotEquals(null, result); PageReference result6 = mc.sortOtherPaginationList(); System.assertNotEquals(null, result); //ListPaginationBase code Coverage Integer currentPageIndex; ListPaginationBase p =new ListPaginationBase(); p.listSize = 7; currentPageIndex = 2; Boolean test1 = p.getHasNext(); Boolean test2 = p.getHasprevious(); Integer test3 = p.getPageCount(); Integer test4 = p.getfirstRowIndex(); PageReference result10 = p.previousAction(); System.assertNotEquals(null, result); PageReference result7 = p.firstAction(); System.assertNotEquals(null, result); PageReference result8 = p.lastAction(); System.assertNotEquals(null, result); PageReference result9 = p.nextAction(); System.assertNotEquals(null, result); p.getObjectPageList(); p.getPageCount(); p.PreviousAction(); p.NextAction(); p.firstAction(); p.LastAction(); p.getHasPrevious(); p.getHasNext(); p.getfirstRowIndex(); test.stopTest(); } public static testMethod void initializePagination() { Account acc = new Account(id = '0018E00000By5vZ', Name ='icrm testing acc'); update acc; opportunity opp = new opportunity ( Name='testing DIE 4/6/2015' , AccountId= acc.Id,StageName = 'Prospecting', type= 'parts', Description= 'describe', Inconterms__c = 'FCA', CloseDate = System.today().addDays(30)); insert opp; PageReference pageRef = Page.Opp_Tabs; Test.setCurrentPage(pageRef); ApexPages.StandardController sc = new ApexPages.StandardController(acc); AccountOpportunityTabExtension mc = new AccountOpportunityTabExtension(sc); ListPaginationBase p=new ListPaginationBase(); PageReference result = mc.NewOpp(); System.assertNotEquals(null, result); PageReference result7 = p.firstAction(); System.assertNotEquals(null, result); PageReference result8 = p.lastAction(); System.assertNotEquals(null, result); PageReference result9 = p.nextAction(); System.assertNotEquals(null, result); PageReference result10 = p.previousAction(); System.assertNotEquals(null, result); p.NextAction(); p.firstAction(); p.LastAction(); p.PreviousAction(); p.getHasPrevious(); p.getHasNext(); p.getfirstRowIndex(); p.getObjectPageList(); p.listSize = 7; } }
- reem sharawy
- November 20, 2016
- Like
- 0
page reference in test class
Hello
I can't have trouble covering my page reference in test class
test class
I can't have trouble covering my page reference in test class
public class AccountInvoiceTabExtension { public ListPaginationBase ConstructionPaginationBaseObject {get; set;} public ListPaginationBase DeltaPaginationBaseObject {get; set;} public ListPaginationBase EnginePowerGenerationPaginationBaseObject {get; set;} public ListPaginationBase MiningPaginationBaseObject {get; set;} public ListPaginationBase ProductSupportPaginationBaseObject {get; set;} public ListPaginationBase SamsungPaginationBaseObject {get; set;} public ListPaginationBase OtherPaginationBaseObject {get; set;} public List<InvoiceWrapper> ConstructionInvoiceList {get; set;} public List<InvoiceWrapper> DeltaInvoiceList {get; set;} public List<InvoiceWrapper> EnginePowerGenerationInvoiceList {get; set;} public List<InvoiceWrapper> MiningInvoiceList {get; set;} public List<InvoiceWrapper> ProductSupportInvoiceList {get; set;} public List<InvoiceWrapper> SamsungInvoiceList {get; set;} public List<InvoiceWrapper> OtherInvoiceList {get; set;} public String constructionInvoiceSort {get; set;} public boolean constructionInvoiceSortDesc {get; set;} public String DeltaInvoiceSort {get; set;} public boolean DeltaInvoiceSortDesc {get; set;} public String EnginePowerGenerationInvoiceSort {get; set;} public boolean EnginePowerGenerationInvoiceSortDesc {get; set;} public String MiningInvoiceSort {get; set;} public boolean MiningInvoiceSortDesc {get; set;} public String ProductSupportInvoiceSort {get; set;} public boolean ProductSupportInvoiceSortDesc {get; set;} public String SamsungInvoiceSort {get; set;} public boolean SamsungInvoiceSortDesc {get; set;} public String OtherInvoiceSort {get; set;} public boolean OtherInvoiceSortDesc {get; set;} public Account currentAccount {get; set;} public AccountInvoiceTabExtension(ApexPages.StandardController controller) { currentAccount = (Account) controller.getRecord(); constructionInvoiceSort = 'Name'; constructionInvoiceSortDesc = false; DeltaInvoiceSort = 'Name'; DeltaInvoiceSortDesc = false; EnginePowerGenerationInvoiceSort = 'Name'; EnginePowerGenerationInvoiceSortDesc = false; MiningInvoiceSort = 'Name'; MiningInvoiceSortDesc = false; ProductSupportInvoiceSort = 'Name'; ProductSupportInvoiceSortDesc = false; SamsungInvoiceSort = 'Name'; SamsungInvoiceSortDesc = false; OtherInvoiceSort = 'Name'; OtherInvoiceSortDesc = false; refreshConstructionInvoiceList(); refreshDeltaInvoiceList (); refreshEnginePowerGenerationInvoiceList(); refreshMiningPaginationList(); refreshProductSupportInvoiceList(); refreshSamsungInvoiceList(); refreshOtherInvoiceList(); } public PageReference sortConstructionPaginationList() { refreshConstructionInvoiceList(); return null; } public PageReference sortDeltaPaginationList() { refreshDeltaInvoiceList(); return null; } public PageReference sortEnginePowerGenerationPaginationList() { refreshEnginePowerGenerationInvoiceList(); return null; } public PageReference sortMiningPaginationList() { refreshMiningPaginationList(); return null; } public PageReference sortProductSupportPaginationList() { refreshProductSupportInvoiceList(); return null; } public PageReference sortSamsungPaginationList() { refreshSamsungInvoiceList(); return null; } public PageReference sortOtherPaginationList() { refreshOtherInvoiceList(); return null; } private void refreshConstructionInvoiceList() { getConstructionInvoiceList(); constructionPaginationBaseObject = new ListPaginationBase(); constructionPaginationBaseObject.initializePagination(ConstructionInvoiceList, 20); } private void refreshDeltaInvoiceList() { getDeltaInvoiceList(); DeltaPaginationBaseObject = new ListPaginationBase(); DeltaPaginationBaseObject.initializePagination(DeltaInvoiceList, 20); } private void refreshEnginePowerGenerationInvoiceList() { getEnginePowerGenerationInvoiceList(); EnginePowerGenerationPaginationBaseObject = new ListPaginationBase(); EnginePowerGenerationPaginationBaseObject.initializePagination(EnginePowerGenerationInvoiceList, 20); } private void refreshMiningPaginationList() { getMiningInvoiceList(); MiningPaginationBaseObject = new ListPaginationBase(); MiningPaginationBaseObject.initializePagination(MiningInvoiceList, 20); } private void refreshProductSupportInvoiceList() { getProductSupportInvoiceList (); ProductSupportPaginationBaseObject = new ListPaginationBase(); ProductSupportPaginationBaseObject.initializePagination(ProductSupportInvoiceList, 20); } private void refreshSamsungInvoiceList() { getSamsungInvoiceList(); SamsungPaginationBaseObject = new ListPaginationBase(); SamsungPaginationBaseObject.initializePagination(SamsungInvoiceList, 20); } private void refreshOtherInvoiceList() { getOtherInvoiceList(); OtherPaginationBaseObject = new ListPaginationBase(); OtherPaginationBaseObject.initializePagination(OtherInvoiceList, 20); } public class InvoiceWrapper { public Id InvoiceId {get; set;} public String orderNumber {get; set;} public Date InvoiceDate {get; set;} public String OrderType {get; set;} public String ModelDescription {get; set;} public String InvoiceType {get; set;} public String OrderTaking {get; set;} public double TotalSellVAT {get; set;} public String CostCenter {get; set;} public String CostCenterDivision {get; set;} public Id ordertakingid {get; set;} } private void getConstructionInvoiceList() { ConstructionInvoiceList = new List<InvoiceWrapper>(); String soqlQuery = 'SELECT Id, Name, Cost_Centre_Main_Division__c, Cost_Center_Division__c, Invoice_Date__c, Order_Type__c, Model_Description__c, Invoice_Type__c, Order_Taking__r.name, Order_Taking__r.id, Total_Price_Net__c, Cost_Center__c'; soqlQuery += ' FROM Order_ManPro__c '; soqlQuery += ' WHERE Account_order__c = \'' + currentAccount.Id + '\''; soqlQuery += ' AND Cost_Centre_Main_Division__c = \'CONSTRUCTION ALL\''; soqlQuery += ' ORDER BY ' + constructionInvoiceSort; if (constructionInvoiceSortDesc) soqlQuery += ' DESC'; for (Order_ManPro__c constInvoice : Database.query(soqlQuery)) { InvoiceWrapper wrapper = new InvoiceWrapper(); wrapper.InvoiceId = constInvoice.Id; wrapper.orderNumber = constInvoice.Name; wrapper.InvoiceDate = constInvoice.Invoice_Date__c; wrapper.OrderType = constInvoice.Order_Type__c; wrapper.ModelDescription = constInvoice.Model_Description__c; wrapper.InvoiceType = constInvoice.Invoice_Type__c; wrapper.OrderTaking = constInvoice.Order_Taking__r.name; wrapper.ordertakingid = constInvoice.Order_Taking__r.id; wrapper.TotalSellVAT = constInvoice.Total_Price_Net__c; wrapper.CostCenter = constInvoice.Cost_Center__c; wrapper.CostCenterDivision = constInvoice.Cost_Center_Division__c; ConstructionInvoiceList.add(wrapper); } } private void getDeltaInvoiceList() { DeltaInvoiceList = new List<InvoiceWrapper>(); String soqlQuery = 'SELECT Id, Name, Cost_Centre_Main_Division__c, Account_order__c, Cost_Center_Division__c, Invoice_Date__c, Order_Type__c, Model_Description__c, Invoice_Type__c, Order_Taking__r.name, Total_Price_Net__c, Cost_Center__c'; soqlQuery += ' FROM Order_ManPro__c '; soqlQuery += ' WHERE Account_order__c = \'' + currentAccount.Id + '\''; soqlQuery += ' AND Cost_Centre_Main_Division__c = \'DELTA\''; soqlQuery += ' ORDER BY ' + DeltaInvoiceSort; if (DeltaInvoiceSortDesc) soqlQuery += ' DESC'; for (Order_ManPro__c DeltaInvoice : Database.query(soqlQuery)) { InvoiceWrapper wrapper = new InvoiceWrapper(); wrapper.InvoiceId = DeltaInvoice.Id; wrapper.orderNumber = DeltaInvoice.Name; wrapper.InvoiceDate = DeltaInvoice.Invoice_Date__c; wrapper.OrderType = DeltaInvoice.Order_Type__c; wrapper.ModelDescription = DeltaInvoice.Model_Description__c; wrapper.InvoiceType = DeltaInvoice.Invoice_Type__c; wrapper.OrderTaking = DeltaInvoice.Order_Taking__r.name; wrapper.ordertakingid = DeltaInvoice.Order_Taking__r.id; wrapper.TotalSellVAT = DeltaInvoice.Total_Price_Net__c; wrapper.CostCenter = DeltaInvoice.Cost_Center__c; wrapper.CostCenterDivision = DeltaInvoice.Cost_Center_Division__c; DeltaInvoiceList.add(wrapper); } } private void getEnginePowerGenerationInvoiceList() { EnginePowerGenerationInvoiceList = new List<InvoiceWrapper>(); String soqlQuery = 'SELECT Id, Name, Cost_Centre_Main_Division__c, Account_order__c, Cost_Center_Division__c, Invoice_Date__c, Order_Type__c, Model_Description__c, Invoice_Type__c, Order_Taking__r.name, Total_Price_Net__c, Cost_Center__c'; soqlQuery += ' FROM Order_ManPro__c '; soqlQuery += ' WHERE Account_order__c = \'' + currentAccount.Id + '\''; soqlQuery += ' AND Cost_Centre_Main_Division__c = \'ENGINE POWER GENERATION\''; soqlQuery += ' ORDER BY ' + EnginePowerGenerationInvoiceSort; if (EnginePowerGenerationInvoiceSortDesc) soqlQuery += ' DESC'; for (Order_ManPro__c EnginePowerGenerationInvoice : Database.query(soqlQuery)) { InvoiceWrapper wrapper = new InvoiceWrapper(); wrapper.InvoiceId = EnginePowerGenerationInvoice.Id; wrapper.orderNumber = EnginePowerGenerationInvoice.Name; wrapper.InvoiceDate = EnginePowerGenerationInvoice.Invoice_Date__c; wrapper.OrderType = EnginePowerGenerationInvoice.Order_Type__c; wrapper.ModelDescription = EnginePowerGenerationInvoice.Model_Description__c; wrapper.InvoiceType = EnginePowerGenerationInvoice.Invoice_Type__c; wrapper.OrderTaking = EnginePowerGenerationInvoice.Order_Taking__r.name; wrapper.ordertakingid = EnginePowerGenerationInvoice.Order_Taking__r.id; wrapper.TotalSellVAT = EnginePowerGenerationInvoice.Total_Price_Net__c; wrapper.CostCenter = EnginePowerGenerationInvoice.Cost_Center__c; wrapper.CostCenterDivision = EnginePowerGenerationInvoice.Cost_Center_Division__c; EnginePowerGenerationInvoiceList.add(wrapper); } } private void getMiningInvoiceList() { MiningInvoiceList = new List<InvoiceWrapper>(); String soqlQuery = 'SELECT Id, Name, Cost_Centre_Main_Division__c, Account_order__c, Cost_Center_Division__c, Invoice_Date__c, Order_Type__c, Model_Description__c, Invoice_Type__c, Order_Taking__r.name, Total_Price_Net__c, Cost_Center__c'; soqlQuery += ' FROM Order_ManPro__c '; soqlQuery += ' WHERE Account_order__c = \'' + currentAccount.Id + '\''; soqlQuery += ' AND Cost_Centre_Main_Division__c = \'MINING\''; soqlQuery += ' ORDER BY ' + MiningInvoiceSort; if (MiningInvoiceSortDesc) soqlQuery += ' DESC'; for (Order_ManPro__c MiningInvoice : Database.query(soqlQuery)) { InvoiceWrapper wrapper = new InvoiceWrapper(); wrapper.InvoiceId = MiningInvoice.Id; wrapper.orderNumber = MiningInvoice.Name; wrapper.InvoiceDate = MiningInvoice.Invoice_Date__c; wrapper.OrderType = MiningInvoice.Order_Type__c; wrapper.ModelDescription = MiningInvoice.Model_Description__c; wrapper.InvoiceType = MiningInvoice.Invoice_Type__c; wrapper.OrderTaking = MiningInvoice.Order_Taking__r.name; wrapper.ordertakingid = MiningInvoice.Order_Taking__r.id; wrapper.TotalSellVAT = MiningInvoice.Total_Price_Net__c; wrapper.CostCenter = MiningInvoice.Cost_Center__c; wrapper.CostCenterDivision = MiningInvoice.Cost_Center_Division__c; MiningInvoiceList.add(wrapper); } } private void getProductSupportInvoiceList() { ProductSupportInvoiceList = new List<InvoiceWrapper>(); String soqlQuery = 'SELECT Id, Name, Cost_Centre_Main_Division__c, Account_order__c, Cost_Center_Division__c, Invoice_Date__c, Order_Type__c, Model_Description__c, Invoice_Type__c, Order_Taking__r.name, Total_Price_Net__c, Cost_Center__c'; soqlQuery += ' FROM Order_ManPro__c '; soqlQuery += ' WHERE Account_order__c = \'' + currentAccount.Id + '\''; soqlQuery += ' AND Cost_Centre_Main_Division__c = \'PRODUCT SUPPORT\''; soqlQuery += ' ORDER BY ' + ProductSupportInvoiceSort; if (ProductSupportInvoiceSortDesc) soqlQuery += ' DESC'; for (Order_ManPro__c ProductSupportInvoice : Database.query(soqlQuery)) { InvoiceWrapper wrapper = new InvoiceWrapper(); wrapper.InvoiceId = ProductSupportInvoice.Id; wrapper.orderNumber = ProductSupportInvoice.Name; wrapper.InvoiceDate = ProductSupportInvoice.Invoice_Date__c; wrapper.OrderType = ProductSupportInvoice.Order_Type__c; wrapper.ModelDescription = ProductSupportInvoice.Model_Description__c; wrapper.InvoiceType = ProductSupportInvoice.Invoice_Type__c; wrapper.OrderTaking = ProductSupportInvoice.Order_Taking__r.name; wrapper.ordertakingid = ProductSupportInvoice.Order_Taking__r.id; wrapper.TotalSellVAT = ProductSupportInvoice.Total_Price_Net__c; wrapper.CostCenter = ProductSupportInvoice.Cost_Center__c; wrapper.CostCenterDivision = ProductSupportInvoice.Cost_Center_Division__c; ProductSupportInvoiceList.add(wrapper); } } private void getSamsungInvoiceList() { SamsungInvoiceList = new List<InvoiceWrapper>(); String soqlQuery = 'SELECT Id, Name, Cost_Centre_Main_Division__c, Account_order__c, Cost_Center_Division__c, Invoice_Date__c, Order_Type__c, Model_Description__c, Invoice_Type__c, Order_Taking__r.name, Total_Price_Net__c, Cost_Center__c'; soqlQuery += ' FROM Order_ManPro__c '; soqlQuery += ' WHERE Account_order__c = \'' + currentAccount.Id + '\''; soqlQuery += ' AND Cost_Centre_Main_Division__c = \'SAMSUNG\''; soqlQuery += ' ORDER BY ' + SamsungInvoiceSort; if (SamsungInvoiceSortDesc) soqlQuery += ' DESC'; for (Order_ManPro__c SamsungInvoice : Database.query(soqlQuery)) { InvoiceWrapper wrapper = new InvoiceWrapper(); wrapper.InvoiceId = SamsungInvoice .Id; wrapper.orderNumber = SamsungInvoice .Name; wrapper.InvoiceDate = SamsungInvoice .Invoice_Date__c; wrapper.OrderType = SamsungInvoice .Order_Type__c; wrapper.ModelDescription = SamsungInvoice .Model_Description__c; wrapper.InvoiceType = SamsungInvoice.Invoice_Type__c; wrapper.OrderTaking = SamsungInvoice.Order_Taking__r.name; wrapper.ordertakingid = SamsungInvoice.Order_Taking__r.id; wrapper.TotalSellVAT = SamsungInvoice.Total_Price_Net__c; wrapper.CostCenter = SamsungInvoice.Cost_Center__c; wrapper.CostCenterDivision = SamsungInvoice.Cost_Center_Division__c; SamsungInvoiceList.add(wrapper); } } private void getOtherInvoiceList() { OtherInvoiceList = new List<InvoiceWrapper>(); String soqlQuery = 'SELECT Id, Name, Cost_Centre_Main_Division__c, Account_order__c, Cost_Center_Division__c, Invoice_Date__c, Order_Type__c, Model_Description__c, Invoice_Type__c, Order_Taking__r.name, Total_Price_Net__c, Cost_Center__c'; soqlQuery += ' FROM Order_ManPro__c '; soqlQuery += ' WHERE Account_order__c = \'' + currentAccount.Id + '\''; soqlQuery += ' AND Cost_Centre_Main_Division__c = \'OTHERS MISC - INTERNAL\''; soqlQuery += ' ORDER BY ' + OtherInvoiceSort; if (OtherInvoiceSortDesc) soqlQuery += ' DESC'; for (Order_ManPro__c OtherInvoice : Database.query(soqlQuery)) { InvoiceWrapper wrapper = new InvoiceWrapper(); wrapper.InvoiceId = OtherInvoice.Id; wrapper.orderNumber = OtherInvoice.Name; wrapper.InvoiceDate = OtherInvoice.Invoice_Date__c; wrapper.OrderType = OtherInvoice.Order_Type__c; wrapper.ModelDescription = OtherInvoice.Model_Description__c; wrapper.InvoiceType = OtherInvoice.Invoice_Type__c; wrapper.OrderTaking = OtherInvoice.Order_Taking__r.name; wrapper.ordertakingid = OtherInvoice.Order_Taking__r.id; wrapper.TotalSellVAT = OtherInvoice.Total_Price_Net__c; wrapper.CostCenter = OtherInvoice.Cost_Center__c; wrapper.CostCenterDivision = OtherInvoice.Cost_Center_Division__c; OtherInvoiceList.add(wrapper); } } public pageReference NewInvoice() { PageReference pageRef = new PageReference('/a0J/e?CF00Nb0000005YEDS_lkid=' + currentAccount.Id + '&CF00Nb0000005YEDS=' + currentAccount.Name); pageRef.setRedirect(true); return pageRef; } }
test class
@isTest (SeeAllData=true) private class TESTAccountInvoiceTabExtension { static testmethod void AccountInvoiceTabExtension_Test (){ test.StartTest(); Account acc = new Account(Name ='icrm testing acc'); insert acc; Order_ManPro__c constInvoice = new Order_ManPro__c ( Name='1234', Account_order__c= acc.Id, Cost_Centre_Main_Division__c ='CONSTRUCTION ALL', Cost_Center_ManPRO__c = 'a0e8E000001OZuM', Cost_Center_Division__c = 'CONSTRUCTION ALL',Cost_Centre_Description__c = 'Machine Rental (Const)',Cost_Center__c = 'CMM', CurrencyIsoCode = 'USD', Invoice_Date__c = System.today().addDays(30),Order_Type__c = 'rergg', Model_Description__c = 'desc', Order_Taking__c = '005b00000010h3o', External_Order_ID__c = '9876000'); insert constInvoice; Order_ManPro__c DeltaInvoice = new Order_ManPro__c ( Name='234' , Account_order__c= acc.Id, Cost_Centre_Main_Division__c ='DELTA', Cost_Center_ManPRO__c = 'a0e8E000001OZuM', Cost_Center_Division__c = 'AGRICULTURE',Cost_Centre_Description__c = 'John Deer',Cost_Center__c = 'NMB', CurrencyIsoCode = 'USD', Invoice_Date__c = System.today().addDays(30),Order_Type__c = 'rergg', Model_Description__c = 'desc', Order_Taking__c = '005b00000010h3o', External_Order_ID__c = '98760900'); insert DeltaInvoice; Order_ManPro__c EnginePowerGenerationInvoice = new Order_ManPro__c (Name='234' , Account_order__c= acc.Id, Cost_Centre_Main_Division__c ='ENGINE POWER GENERATION', Cost_Center_ManPRO__c = 'a0e8E000001OZvj', Cost_Center_Division__c = 'MARINE',Cost_Centre_Description__c = 'Marine Engines',Cost_Center__c = 'CEC', CurrencyIsoCode = 'USD', Invoice_Date__c = System.today().addDays(30),Order_Type__c = 'rergg', Model_Description__c = 'desc', Order_Taking__c = '005b00000010h3o', External_Order_ID__c = '1'); insert EnginePowerGenerationInvoice; Order_ManPro__c MiningInvoice = new Order_ManPro__c (Name='234' , Account_order__c= acc.Id, Cost_Centre_Main_Division__c ='MINING', Cost_Center_ManPRO__c = 'a0e8E000001OZw8', Cost_Center_Division__c = 'MINING',Cost_Centre_Description__c = 'Rental machines Mining',Cost_Center__c = 'CMI', CurrencyIsoCode = 'USD', Invoice_Date__c = System.today().addDays(30),Order_Type__c = 'rergg', Model_Description__c = 'desc', Order_Taking__c = '005b00000010h3o', External_Order_ID__c = '9'); insert MiningInvoice; Order_ManPro__c ProductSupportInvoice = new Order_ManPro__c (Name='234' , Account_order__c= acc.Id, Cost_Centre_Main_Division__c ='PRODUCT SUPPORT', Cost_Center_ManPRO__c = 'a0e8E000001OZvV', Cost_Center_Division__c = 'PRODUCT SUPPORT',Cost_Centre_Description__c = 'Service Admin Mining',Cost_Center__c = 'CS2', CurrencyIsoCode = 'USD', Invoice_Date__c = System.today().addDays(30),Order_Type__c = 'rergg', Model_Description__c = 'desc', Order_Taking__c = '005b00000010h3o', External_Order_ID__c = '2'); insert ProductSupportInvoice; Order_ManPro__c SamsungInvoice = new Order_ManPro__c (Name='234' , Account_order__c= acc.Id, Cost_Centre_Main_Division__c ='SAMSUNG', Cost_Center_ManPRO__c = 'a0e8E000001OZxo', Cost_Center_Division__c = 'SAMSUNG',Cost_Centre_Description__c = 'Audio and Video Products',Cost_Center__c = 'TEC', CurrencyIsoCode = 'USD', Invoice_Date__c = System.today().addDays(30),Order_Type__c = 'rergg', Model_Description__c = 'desc', Order_Taking__c = '005b00000010h3o', External_Order_ID__c = '4'); insert SamsungInvoice; Order_ManPro__c OtherInvoice = new Order_ManPro__c (Name='234' , Account_order__c= acc.Id, Cost_Centre_Main_Division__c ='OTHERS MISC - INTERNAL', Cost_Center_ManPRO__c = 'a0e8E000001OZuZ', Cost_Center_Division__c = 'OTHERS MISC - INTERNAL',Cost_Centre_Description__c = 'Internal Sales Reps',Cost_Center__c = 'ZSR', CurrencyIsoCode = 'USD', Invoice_Date__c = System.today().addDays(30),Order_Type__c = 'rergg', Model_Description__c = 'desc', Order_Taking__c = '005b00000010h3o', External_Order_ID__c = '6'); insert OtherInvoice; PageReference pref = Page.Invoice_Tabs; pref.getParameters().put('id', acc.id); Test.setCurrentPage(pref); ApexPages.StandardController sc = new ApexPages.StandardController(acc); AccountInvoiceTabExtension mc = new AccountInvoiceTabExtension(sc); PageReference result = AccountInvoiceTabExtension.autoRun(); System.assertNotEquals(null, result); test.stopTest(); } }
- reem sharawy
- November 14, 2016
- Like
- 0
command button open new tab
Hello
I added a new button on my page to be able to create new opportunity from a visualforce page which replace the opportunity related leist on the account detailed page, the problem is that button doesn't open a new tab and opens in the exisiting Vf page
I added a new button on my page to be able to create new opportunity from a visualforce page which replace the opportunity related leist on the account detailed page, the problem is that button doesn't open a new tab and opens in the exisiting Vf page
<apex:page standardController="Account" extensions="AccountOpportunityTabExtension"> <html xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> <apex:form style="height: 800px;"> <apex:tabPanel > <!-- Add Different Tabs Like the one below --> <apex:tab label="{!$Label.Construction_All_Opportunity}" style="overflow: auto; height: auto;"> <apex:pageBlock > <apex:commandButton value="New" action="/apex/Opp_layout_new_edit?oppId={!Account.id}"/> <!--<Apex:commandButton value="New" onclick="window.open=(/apex/Opp_layout_new_edit?oppId={!Account.id}','_blank')" /> --> <apex:pageBlockSection id="contructionSection" collapsible="false" columns="1"> <apex:pageBlockTable value="{!constructionPaginationBaseObject.objectPageList}" var="opportunity"> <!--<apex:commandButton> <apex:commandLink value="New" action="/apex/Opp_layout_new_edit?oppId={!opportunity['opportunityId']}" target="_blank"/> </apex:commandButton> --> <apex:column > <apex:outputLink title="" value="/{!opportunity['opportunityId']}/e?retURL=/apex/{!$CurrentPage.Name}" style="font-weight:bold" target="_blank">Edit</apex:outputLink> </apex:column> <apex:column headerValue="Opportunity Name"> <apex:commandLink action="/{!opportunity['opportunityId']}" value="{!opportunity['OpportunityName']}" target="_blank"/> </apex:column> <!--<apex:column headerValue="Purchase Type" value="{!opportunity['PurchaseType']}" />--> <apex:column headerValue="Stage" value="{!opportunity['StageName']}" /> <apex:column headerValue="Amount" value="{!opportunity['Amount']}" /> <apex:column headerValue="Order Date" > <apex:outputText value="{0,date,dd/MM/yyyy}"> <apex:param value="{!opportunity['CloseDate']}" /> </apex:outputText> </apex:column> <apex:column headerValue="Owner Full Name"> <apex:commandLink action="/{!opportunity['opportunityId']}" value="{!opportunity['Owner']}" target="_blank"/> </apex:column> </apex:pageBlockTable> <apex:outputPanel > <apex:commandButton value="|< First" action="{!constructionPaginationBaseObject.firstAction}" reRender="contructionSection" disabled="{!NOT(constructionPaginationBaseObject.hasPrevious)}" /> <apex:commandButton value="< Previous" action="{!constructionPaginationBaseObject.previousAction}" reRender="contructionSection" disabled="{!NOT(constructionPaginationBaseObject.hasPrevious)}" /> <apex:outputText value="Page {0} of {1}"> <apex:param value="{!constructionPaginationBaseObject.currentPageIndex + 1}"/> <!-- Adding 1 because this is zero indexed --> <apex:param value="{!constructionPaginationBaseObject.pageCount}"/> </apex:outputText> <apex:commandButton value="Next >" action="{!constructionPaginationBaseObject.nextAction}" reRender="contructionSection" disabled="{!NOT(constructionPaginationBaseObject.hasNext)}" /> <apex:commandButton value="Last >|" action="{!constructionPaginationBaseObject.lastAction}" reRender="contructionSection" disabled="{!NOT(constructionPaginationBaseObject.hasNext)}" /> </apex:outputPanel> </apex:pageBlockSection> </apex:pageBlock> </apex:tab> </apex:tabPanel> </apex:form> </html> </apex:page>
- reem sharawy
- October 18, 2016
- Like
- 0
related opportunities with pagination
hi
I am trying to create a vf page to fetch related opportunities for specific account and to add pagination.
Whenever I try to save my code I get the below error:
Error: Compile Error: Method does not exist or incorrect signature: [ListPaginationBase].initializePagination(List<NewStockTransferExtension.materialWrapperList>, Integer)
I am trying to create a vf page to fetch related opportunities for specific account and to add pagination.
Whenever I try to save my code I get the below error:
Error: Compile Error: Method does not exist or incorrect signature: [ListPaginationBase].initializePagination(List<NewStockTransferExtension.materialWrapperList>, Integer)
public class NewStockTransferExtension{ public ListPaginationBase ConstructionOpportunityList {get; set;} public list<materialWrapperList> materialWrapperList{get;set;} public Account currentAccount {get; set;} public NewStockTransferExtension(ApexPages.StandardController controller) { ConstructionOpportunityList = new ListPaginationBase(); currentAccount = (Account) controller.getRecord(); ConstructionOpportunityList.initializePagination(materialWrapperList, 20); } public class materialWrapperList { public boolean checked{get;set;} Public Opportunity ConstructionOpportunityList {get;set;} public materialWrapperList(Opportunity ConstructionOpportunityList ){ this.ConstructionOpportunityList = ConstructionOpportunityList ; } } }
- reem sharawy
- October 11, 2016
- Like
- 0
Test Class for pagination
Hi folks,
Can anyone tell me how to write the test class for pagination?
Below is my test class which covers 85% but it didnt covers the hasnext,previous and pagenumber method.
Controller:
Thanks in advance
Karthick
Can anyone tell me how to write the test class for pagination?
Below is my test class which covers 85% but it didnt covers the hasnext,previous and pagenumber method.
@isTest(SeeAllData=true) public class PaginationControllerTest { public static testMethod void testSearchAccount() { PageReference pageRef = Page.TestPagination; Test.setCurrentPage(pageRef); // Instantiate a new controller with all parameters in the page PaginationController p=new PaginationController (); p.getAccountList(); p.Next(); p.First(); p.Last(); p.Previous(); p.Cancel(); p.con.getHasPrevious(); p.con.getHasNext(); p.con.getPageNumber(); } }
Controller:
public class PaginationController { public ApexPages.StandardSetController con { get { if(con == null) { con = new ApexPages.StandardSetController(Database.getQueryLocator([Select Id, Name,Type FROM Account])); con.setPageSize(5); } return con; } set; } public List<Account> getAccountList(){ return (List<Account>)con.getRecords(); } public Boolean hasNext { get { return con.getHasNext(); } set; } public Boolean hasPrevious { get { return con.getHasPrevious(); } set; } public Integer pageNumber { get { return con.getPageNumber(); } set; } public void first() { con.first(); } public void last() { con.last(); } public void previous() { con.previous(); } public void next() { con.next(); } public void cancel() { con.cancel(); } }
Thanks in advance
Karthick
- SS Karthick
- December 09, 2014
- Like
- 0