You need to sign in to do that
Don't have an account?
Ruchie
Help on the Test Method for VF Controller
Hi All,
Can anybody help me in writing the test method for the controller below, as i am new to this:
public class Cnrl_Con_Inv { List<List<Contact>> listAccount = new List<List<Contact>>(); List<Contact> accTemp; String txtSearch=System.currentPageReference().getParameters().get('txt'); Integer intPageSize = 20; Integer intCount = 0; Integer intLimit = 13; Integer intListSize; String []strHeader = new String[]{'"Name"', '"Account"', '"Country"','"City"','"Title"','"InvId"','"ConId"'}; String []strTemp = new String[]{}; String strTemp1 = '0'; Integer intTemp = -1; Integer intTemp1 = -1; String pagingStatus = ''; public String objAssignValues {set;get;} public PageReference AWReference() { intTemp = 0; try{ accTemp = new List<Contact>(); system.debug('ABCDEFGH $$$$$$'); for(Contact a : [Select c.Name,c.Title, c.LastName, c.FirstName, c.MailingCountry, c.MailingCity, c.Id, c.Account.Name, c.AccountId From Contact c where c.FirstName like : txtSearch +'%' or c.LastName like : txtSearch +'%']) { intCount++; if(accTemp.size() < intPageSize) { accTemp.add(a); } else { listAccount.add(accTemp); accTemp = new List<Contact>(); accTemp.add(a); } } listAccount.add(accTemp); intListSize = listAccount.size(); system.debug(intListSize); if(intCount <= intPageSize) { strTemp1 = '3'; } } catch(Exception e) { system.debug('Error Ocured: ' + e); } return null; } List<List<Account>> listAcc = new List<List<Account>>(); List<Account> AccVal; String []strAccHeader = new String[]{'"Name"', '"Country"','"Phone-No"'}; public PageReference AccRecAW() { intTemp1 = 0; // intPageSize = (pageSizeVal==null)?(20):pageSizeVal; try { AccVal = new List<Account>(); for(Account A : [Select a.Id, a.Name, a.Phone, a.BillingCountry From Account a where a.Name like : txtSearch +'%' ]) { intCount++; if(AccVal.size() < intPageSize) { AccVal.add(A); } else { listAcc.add(AccVal); AccVal = new List<Account>(); AccVal.add(A); } } listAcc.add(AccVal); intListSize = listAcc.size(); if(intCount <= intPageSize) { strTemp1 = '3'; } } catch (Exception e) { system.debug('Error Ocured: ' + e); } return null; } public PageReference AWReferenceCon() { intTemp = 0; // intPageSize = (pageSizeVal==null)?(20):pageSizeVal;
try{ accTemp = new List<Contact>(); for(Contact f : [Select c.Name,c.Title, c.LastName, c.FirstName, c.MailingCountry, c.MailingCity, c.Id, c.Account.Name, c.AccountId From Contact c where c.AccountId = : objAssignValues ]) { intCount++; if(accTemp.size() < intPageSize) { accTemp.add(f); } else { listAccount.add(accTemp); accTemp = new List<Contact>(); accTemp.add(f); } } listAccount = new List<List<Contact>>(); listAccount.add(accTemp); intListSize = listAccount.size(); if(intCount <= intPageSize) { strTemp1 = '3'; } } catch(Exception e) { system.debug('Error Ocured: ' + e); } return null; } public String[] getAccRecord() { if( intTemp1 == -1) { AccRecAW(); } strTemp.clear(); for(Integer w=0; w<listAcc[intTemp1].size(); w++) strTemp.add('["<a href=\'javascript:#\'>'+(listAcc[intTemp1][w].Name== null?'':listAcc[intTemp1][w].Name)+'</a>", "'+(listAcc[intTemp1][w].BillingCountry == null?'':listAcc[intTemp1][w].BillingCountry)+'", "'+(listAcc[intTemp1][w].Phone== null?'':listAcc[intTemp1][w].Phone)+'", "'+(listAcc[intTemp1][w].Id== null?'':listAcc[intTemp][w].Id)+'"]'); //strTemp.add('["<a href=\'javascript:#\'>'+(listAccount[intTemp][w].Name== null?'':listAccount[intTemp][w].Name)+'</a>", "'+(listAccount[intTemp][w].Account.Name== null?'':listAccount[intTemp][w].Account.Name)+'", "'+(listAccount[intTemp][w].MailingCountry== null?'':listAccount[intTemp][w].MailingCountry)+'", "'+(listAccount[intTemp][w].MailingCity== null?'':listAccount[intTemp][w].MailingCity)+'", "'+(listAccount[intTemp][w].Title== null?'':listAccount[intTemp][w].Title)+'", "'+(listAccount[intTemp][w].AccountId== null?'':listAccount[intTemp][w].AccountId)+'", "'+(listAccount[intTemp][w].Id== null?'':listAccount[intTemp][w].Id)+'"]'); //strTemp.add('["<a href=\'javascript:selLink();\'>'+listAccount[intTemp][w].Who.Name+'</a>", "'+listAccount[intTemp][w].InvestorName__c+'", "'+listAccount[intTemp][w].DealName__c+'", "'+listAccount[intTemp][w].Owner.Name+'", "'+listAccount[intTemp][w].Description+'"]'); if(strTemp == null) return new string[]{'"No Data"'}; else { pagingStatus = 'Displaying ' + (intTemp1*intPageSize+1) + ' - ' + ((intTemp1*intPageSize)+listAccount[intTemp1].size()) + ' of ' + intCount; return strTemp; } } public String getstrTemp1() { return strTemp1; } public PageReference first() { if(intTemp > 0) { strTemp1 = '0'; intTemp = 0; } return null; } public PageReference increment() { if(intTemp < intListSize - 1) { strTemp1 = '1'; intTemp++; } if(intTemp == intListSize - 1) { strTemp1 = '2'; } return null; } public PageReference decrement() { if(intTemp >=1 ) { strTemp1 = '1'; intTemp--; } if(intTemp == 0 ) { strTemp1 = '0'; } return null; } public PageReference last() { if(intTemp < intListSize - 1) { strTemp1 = '2'; intTemp = intListSize - 1; } return null; } public String getpagingStatus() { return pagingStatus; } public String[] getGetData() { if( intTemp == -1) { AWReference(); } strTemp.clear(); for(Integer w=0; w<listAccount[intTemp].size(); w++) strTemp.add('["<a href=\'javascript:#\'>'+(listAccount[intTemp][w].Name== null?'':listAccount[intTemp][w].Name)+'</a>", "'+(listAccount[intTemp][w].Account.Name== null?'':listAccount[intTemp][w].Account.Name)+'", "'+(listAccount[intTemp][w].MailingCountry== null?'':listAccount[intTemp][w].MailingCountry)+'", "'+(listAccount[intTemp][w].MailingCity== null?'':listAccount[intTemp][w].MailingCity)+'", "'+(listAccount[intTemp][w].Title== null?'':listAccount[intTemp][w].Title)+'", "'+(listAccount[intTemp][w].AccountId== null?'':listAccount[intTemp][w].AccountId)+'", "'+(listAccount[intTemp][w].Id== null?'':listAccount[intTemp][w].Id)+'"]'); //strTemp.add('["<a href=\'javascript:selLink();\'>'+listAccount[intTemp][w].Who.Name+'</a>", "'+listAccount[intTemp][w].InvestorName__c+'", "'+listAccount[intTemp][w].DealName__c+'", "'+listAccount[intTemp][w].Owner.Name+'", "'+listAccount[intTemp][w].Description+'"]'); if(strTemp == null) return new string[]{'"No Data"'}; else { pagingStatus = 'Displaying ' + (intTemp*intPageSize+1) + ' - ' + ((intTemp*intPageSize)+listAccount[intTemp].size()) + ' of ' + intCount; return strTemp; } } public String[] getContactData() { intTemp = -1; AWReferenceCon(); { strTemp.add('["<a href=\'javascript:#\'>'+(listAccount[intTemp][w].Name== null?'':listAccount[intTemp][w].Name)+'</a>", "'+(listAccount[intTemp][w].Account.Name== null?'':listAccount[intTemp][w].Account.Name)+'", "'+(listAccount[intTemp][w].MailingCountry== null?'':listAccount[intTemp][w].MailingCountry)+'", "'+(listAccount[intTemp][w].MailingCity== null?'':listAccount[intTemp][w].MailingCity)+'", "'+(listAccount[intTemp][w].Title== null?'':listAccount[intTemp][w].Title)+'", "'+(listAccount[intTemp][w].AccountId== null?'':listAccount[intTemp][w].AccountId)+'", "'+(listAccount[intTemp][w].Id== null?'':listAccount[intTemp][w].Id)+'"]'); } //strTemp.add('["<a href=\'javascript:selLink();\'>'+listAccount[intTemp][w].Who.Name+'</a>", "'+listAccount[intTemp][w].InvestorName__c+'", "'+listAccount[intTemp][w].DealName__c+'", "'+listAccount[intTemp][w].Owner.Name+'", "'+listAccount[intTemp][w].Description+'"]'); if(strTemp == null) return new string[]{'"No Data"'}; else { pagingStatus = 'Displaying ' + (intTemp*intPageSize+1) + ' - ' + ((intTemp*intPageSize)+listAccount[intTemp].size()) + ' of ' + intCount; return strTemp; } } public String[] getGetHeader() { return strHeader; } public String[] getAccHeader() { return strAccHeader; } }
Thanks in Advance.
There is a section specific on writing test methods for Visualforce Controllers.
http://community.salesforce.com/sforce/board/message?board.id=apex&thread.id=10407