You need to sign in to do that
Don't have an account?

Need quick help with Apex testing
So, I've managed to learn a bit of apex. Now I really need a hand with testing the code so that I can move it to production. Could someone please help me with the following?
public class multiAddCEx {
public Id cID = ApexPages.currentPage().getParameters().get('Id'); //grab the Vendor Bill ID
//Integer count = 0;
string num_name = '';
// Lookup against Available Cost Codes Junction Object
public List<SelectOption> costcodes {get; set;}
public multiAddCEx ()
{
costcodes = new List<SelectOption>() ;
for(Cost_Code_Connection__c cc : [select Cost_Code_Junction2__r.Cost_Code_ID__c , Cost_Code_Percentage__c, id,name from Cost_Code_Connection__c where Cost_Code_Connection__c.Bill_Item_Junction__c =: cID order by Cost_Code_Junction2__r.Cost_Code_ID__c, Cost_Code_Percentage__c ])
{
costcodes.add(new SelectOption(cc.Cost_Code_Junction2__r.Cost_Code_ID__c +' - '+ cc.Cost_Code_Percentage__c +'%',cc.Cost_Code_Junction2__r.Cost_Code_ID__c +' - '+ cc.Cost_Code_Percentage__c +'%' )) ;
}
}
//Lookup to find User Intranet ID in User records
public List<SelectOption> intranetids {get; set;}
{
intranetids = new List<SelectOption>() ;
intranetids.add(new SelectOption('-Select-','-Select-'));
for(User ui : [select Intranet_ID__c , id, name, IsActive from User where IsActive = True order by Intranet_ID__c])
{
if (ui.Intranet_ID__c != null){
num_name = ui.name;
intranetids.add(new SelectOption(ui.Intranet_ID__c, ui.Intranet_ID__c +' - '+ num_name )) ;
}
}
}
List <Bill_Allotment__c> CExList;
public Id getID {get; set;}
public PageReference reset() { //pull at most 8 expense records to show so we don't clutter up the page
CExList = [select name, Bill_Allotment__c.Phone_Number__c , Allotment_Amount__c, Bill_Allotment__c.Allotment_User_Id__c, Bill_Allotment__c.Bill_Cost_Code__c from Bill_Allotment__c where Bill_Item__c =: cID order by createddate limit 0 ];
return null; }
public List <Bill_Allotment__c> getCExs() {
if(CExList == null) reset();
return CExList;
}
public void setAccounts(List <Bill_Allotment__c> cexs) {
CExList = cexs;}
public PageReference save() {//upsert records on save
try{
upsert CExList;
ApexPages.Message myMsg = new ApexPages.message(ApexPages.Severity.Info, 'Records Saved Successfully'); //show confirmation message on save
ApexPages.addMessage(myMsg);
return null;
}
catch(DmlException ex){
ApexPages.addMessages(ex);
}
return null;
}
//ApexPages.Message myMsg = new ApexPages.message(ApexPages.Severity.Info, 'Records Saved Successfully'); //show confirmation message on save
//ApexPages.addMessage(myMsg);
//return null;}
public PageReference cancel() {//close window without upsert
return null;
}
public PageReference add() {
//count++;
CExList.add(New Bill_Allotment__c(Bill_Item__c = cID)); //add records to Bill Items and associate with current Bill
return null; }
//public Integer getCount() {
//return count;
// }
}
public class multiAddCEx {
public Id cID = ApexPages.currentPage().getParameters().get('Id'); //grab the Vendor Bill ID
//Integer count = 0;
string num_name = '';
// Lookup against Available Cost Codes Junction Object
public List<SelectOption> costcodes {get; set;}
public multiAddCEx ()
{
costcodes = new List<SelectOption>() ;
for(Cost_Code_Connection__c cc : [select Cost_Code_Junction2__r.Cost_Code_ID__c , Cost_Code_Percentage__c, id,name from Cost_Code_Connection__c where Cost_Code_Connection__c.Bill_Item_Junction__c =: cID order by Cost_Code_Junction2__r.Cost_Code_ID__c, Cost_Code_Percentage__c ])
{
costcodes.add(new SelectOption(cc.Cost_Code_Junction2__r.Cost_Code_ID__c +' - '+ cc.Cost_Code_Percentage__c +'%',cc.Cost_Code_Junction2__r.Cost_Code_ID__c +' - '+ cc.Cost_Code_Percentage__c +'%' )) ;
}
}
//Lookup to find User Intranet ID in User records
public List<SelectOption> intranetids {get; set;}
{
intranetids = new List<SelectOption>() ;
intranetids.add(new SelectOption('-Select-','-Select-'));
for(User ui : [select Intranet_ID__c , id, name, IsActive from User where IsActive = True order by Intranet_ID__c])
{
if (ui.Intranet_ID__c != null){
num_name = ui.name;
intranetids.add(new SelectOption(ui.Intranet_ID__c, ui.Intranet_ID__c +' - '+ num_name )) ;
}
}
}
List <Bill_Allotment__c> CExList;
public Id getID {get; set;}
public PageReference reset() { //pull at most 8 expense records to show so we don't clutter up the page
CExList = [select name, Bill_Allotment__c.Phone_Number__c , Allotment_Amount__c, Bill_Allotment__c.Allotment_User_Id__c, Bill_Allotment__c.Bill_Cost_Code__c from Bill_Allotment__c where Bill_Item__c =: cID order by createddate limit 0 ];
return null; }
public List <Bill_Allotment__c> getCExs() {
if(CExList == null) reset();
return CExList;
}
public void setAccounts(List <Bill_Allotment__c> cexs) {
CExList = cexs;}
public PageReference save() {//upsert records on save
try{
upsert CExList;
ApexPages.Message myMsg = new ApexPages.message(ApexPages.Severity.Info, 'Records Saved Successfully'); //show confirmation message on save
ApexPages.addMessage(myMsg);
return null;
}
catch(DmlException ex){
ApexPages.addMessages(ex);
}
return null;
}
//ApexPages.Message myMsg = new ApexPages.message(ApexPages.Severity.Info, 'Records Saved Successfully'); //show confirmation message on save
//ApexPages.addMessage(myMsg);
//return null;}
public PageReference cancel() {//close window without upsert
return null;
}
public PageReference add() {
//count++;
CExList.add(New Bill_Allotment__c(Bill_Item__c = cID)); //add records to Bill Items and associate with current Bill
return null; }
//public Integer getCount() {
//return count;
// }
}
Thanks
Choose it as best answer if it has helped you
All Answers
Thanks
Choose it as best answer if it has helped you
Thank you. I spent another 30 minutes on the code that you provided and made it work for me. It may not be perfect but it is my first test code and IT WORKS!
Below is the final: