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

Test class for Visualforce controller extension
Hi Everyone,
Good day!
I would like to request for assistance in creating a test class for this VF controller extension.
The draft test class
@isTest //This is a test case for a situation where a lead will be converted. The developer must explicitly call the convert lead //method to simulate the user action. private class BillofLadingtest4Extensiontest { public List<Bill_of_Lading__c> bol {get;set;} static testMethod void BillofLadingtest4Extension() { //test.startTest(); Bill_of_Lading__c b = new Bill_of_Lading__c(Name ='testbilloflading'); insert b; update b; Skid__c skd = new Skid__c(Name ='skid', Bill_of_Lading__c = b.Id, Dimension__c ='dimension 1', Number_of_Pieces__c =1, UOM__c ='uom 1', Weight__c =12); insert skd; ApexPages.StandardController con = new ApexPages.StandardController(b); BillofLadingtest4Extension bole = new BillofLadingtest4Extension(con); PageReference ref = bole.save(); PageReference ref1 = bole.saveAndExit(); PageReference ref2 = bole.deliverAsPDF(); PageReference ref3 = null; BillofLadingtest4Extension billofl = new BillofLadingtest4Extension(con); PageReference result = billofl.save(); PageReference ref9 = new PageReference('/apex/billofladingtest05222013?Id=' + b.Id); Test.setCurrentPage(ref9); PageReference pageRef = Page.Billofladingtest05222013; Test.setCurrentPage(pageRef); pageRef.setRedirect(true); //test.stopTest(); } }
These are the untested parts of the extension
public boolean updateSkids() { boolean result=true; if (null!=skids) { // TODO: should work out what's changed and then save, easier to update everything for prototype List<Skid__c> updSkids=new List<Skid__c>(); try { update skids; } catch (Exception e) { String msg=e.getMessage(); integer pos; // if its field validation, this will be added to the messages by default if (-1==(pos=msg.indexOf('FIELD_CUSTOM_VALIDATION_EXCEPTION, '))) { ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, msg)); } result=false; } } return result; }
public void newSkid() { if (updateSkids()) { Skid__c skid=new Skid__c(Name=newSkidName, Dimension__c=newSkidDimension, Number_of_Pieces__c=newSkidNumberofPieces, UOM__c=newskiduom, Weight__c=newskidweight, Bill_of_Lading__c=getBillofLading().id); insert skid; newSkidName=null; newSkidDimension=null; newSkidNumberofPieces=null; newskidbilloflading=null; newskiduom=null; newskidweight=null; skids=null; } }
public void deleteSkid() { if (updateSkids()) { if (null!=chosenskidId) { Skid__c skid=new Skid__c(Id=chosenskidId); delete skid; skids=null; chosenskidId=null; } } }
public List<Skid__c> getSkids() { if ( (null!=getBillofLading().id) && (skids == null) ) { skids=[SELECT Id, Name, Bill_of_Lading__c, Dimension__c, Number_of_Pieces__c, UOM__c, Weight__c FROM Skid__c WHERE Id =: getBillofLading().id ORDER BY CreatedDate]; } return skids; }
public String getChooserender() { if (ApexPages.currentPage().getParameters().get('p') != null) return 'pdf'; else return null; }
Can't say thanks enough, but again, thanks in advance.
Regards,
Pfang