function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
MargiroMargiro 

Test Code for a Class

Im having a problem as explained here. I was told that it is because of a lack of test coverage but Im new to this and dont know how to write test code to cover the class. How do I write this code? Thanks in advance for your help!

-Matt

 

Here is the code for my class:

 

public class GLeadExtension { public Lead Lead1 ; public GLeadExtension(ApexPages.StandardController controller) { Lead1 = (Lead)controller.getRecord(); Lead1.D1_Owner__c = '0017000000NnIX7'; Lead1.D2_Owner__c = '0017000000NnIX7'; } public PageReference step1() { return Page.mhform1; } public PageReference step2() { return Page.mhform2; } public PageReference step3() { return Page.mhform3; } public PageReference step4() { return Page.mhformconfirm; } public PageReference save() { PageReference pdf = Page.mhformconfirm; pdf.getParameters().put('p','p'); pdf.setRedirect(false); Blob b = pdf.getContent(); Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage(); email.setSubject('Conveying Application request'); String [] toAddresses = new String[] {'margiro@piab.com'}; email.setToAddresses(toAddresses); email.setPlainTextBody('An order has been placed for a conveyor'); Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment(); efa.setFileName(Lead1.company + '.pdf'); efa.setBody(b); email.setFileAttachments(new Messaging.EmailFileAttachment[] {efa}); Messaging.SendEmailResult [] r = Messaging.sendEmail(new Messaging.SingleEmailMessage[] {email}); //leadsave(); //this.standardController.save(); insert Lead1; //this is my logic for where I want to go after stuff is saved PageReference nextPage = new PageReference('/apex/mhformendpage'); nextPage .setRedirect(true); return nextpage; //return page.mhformendpage; } }

 

 

 

AlsoDougAlsoDoug

The introduction to writing test coverage is at

 

http://wiki.developerforce.com/index.php/An_Introduction_to_Apex_Code_Test_Methods

 

That would be a good place to start.