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
SunadminSunadmin 

Test controller getting compile errors

Hello, I have a controller creditProcess2 I created for a three column data table for date/time stamped custom fields. The controller has compiled in the sandbox and I am creating the test controller. Here is my code for the test controller:

public class thecreditProcess2Test{
    public static testMethod void testcreditProcess2 () {
    pageReference PageRef = Page.success;
    Test.setcurrentPage(PageRef);
  	creditProcess2 controller = new creditProcess2();
    String nextPage=save.creditProcess2().get.URL(); 
    
     //no parameters and page will fail 
    System.assertEquals ('/apex/failure?error = noParam., nextPage');
    ApexPages.currentPage().get.Parameters().put('qp', 'yyyy'); 
    //enter in test values for the System.Assert 
        creditProcess2 = new creditProcess2();
        creditProcess2.setLastName('lastname');
        creditProcess2.setFirstName('firstname');
        creditProcess2.setCompany('acme');
        creditProcess2.setEmail('firstlast@acme.com');
        nextPage = creditProcess2.save().getUrl();
    //success for new page parameters
    System.assertEquals('/apex/success', nextPage);
    //query for test values
    Lead[] leads = [select id, email from lead where Company = 'acme'];
    System.assertEquals('firstlast@acme.com', leads[0].email);
   }
    }

 

When I compile it I get:

 

Compile Error: Invalid type: thecreditProcess2 at line 5 column 44 

 

Line 5 is the following: creditProcess2 controller = new creditProcess2();

 

I have tried other values for the controller name but nothing seems to be getting past the compile error. Any suggestions? I can include the original controller if needed.

 

Thanks,

WesNolte__cWesNolte__c

Hey

 

Please post the controller too.

 

Wes

SunadminSunadmin

Wes,

here is my original controller. I don't have the SOQL query fully populated because I created the lead custom fields in production but they are not in the sandbox.

 

public class creditProcess2 {
    public String searchResults { get; set; }
    public String displayResults { get; set; }

    public String searchText {get; set;}
    List<Lead> results;

//get results of query
    public List<Lead> getResults() {
        return results;
    }
    public PageReference doSearch() {

    results =[SELECT Name, Email
        FROM Lead LIMIT 10]; 
        return null;
    } 
}

 

thanks

 

Pradeep_NavatarPradeep_Navatar

Try out this sample test code given below :

 

            @isTest

                                                private class thecreditProcess2Test

                                                {

                                                  static testMethod void testcreditProcess2()

                                                  {

                                                                  Lead l = new Lead();

                                                                  ld.firstname= 'testdata';

                                                                  ld.lastname= 'testlastdata';

                                                                  ld.company='acme';

                                                                  ld.Start_Date__c = Date.newInstance(2009,1,25);

                                                                  ld.End_Date__c = Date.newInstance(2009,1,30);

                                                                  insert ld;

                                                                  Id id = ApexPages.currentPage().getParameters().put('Id',controller.Id);

                                                                  creditProcess2 controller = new creditProcess2();

                                                                  PageReference pr = controller.save();

 

                                                  }

                                                }  

 

Hope this helps.          

WesNolte__cWesNolte__c

The test class you've posted and the error message you're getting don't really tie up. It's complaining that you're trying to use a class called "thecreditProcess2" but that's not the case. Did you change the test code before posting?

 

Wes

SunadminSunadmin

Thanks Pradeep,

 

I will give it a shot.

SunadminSunadmin

Wes,

 

should I change the test values in the controller? Forgive my ignorance, this is the first time I have done this.