+ Start a Discussion
jblon1973jblon1973 

Test Class Help Invalid Type Error

I am writing a test class for the following webservice:

global class wsLoad_NDD_Data {
	
	webservice static Patient_Data__c LoadPatientData(String strPatientId, String strFirstName, String strLastName, String strIsBioCal, String strEthnicity, String strAsthma, String strGender, Date dtmDateOfBirth, String strCOPD, Decimal numHeight, Decimal numWeight)// String strsite
	{
		Patient_Data__c insertPatientData = null;
		
		// Look for the Patient_Data_ID__c being passed in.
		List<Patient_Data__c> objPatient = new List<Patient_Data__c>();
            
        objPatient = [SELECT ID, Patient_ID__c FROM Patient_Data__c WHERE Patient_ID__c = :strPatientId];
                
        if(objPatient.size() > 0)
        {
        // Existing Patient.
        Patient_Data__c updatePatientData = [SELECT Patient_ID__c, First_Name__c, Last_Name__c, IsBioCal_Int__c, Ethnicity__c, Asthma__c, Gender__c, Date_of_Birth__c, Height__c, Weight__c, Site__c  FROM Patient_Data__c
        WHERE Patient_ID__c = :strPatientId];
        
        updatePatientData.Patient_ID__c = strPatientId;
		updatePatientData.First_Name__c = strFirstName;
		updatePatientData.Last_Name__c = strLastName;
		updatePatientData.IsBioCal_Int__c = strIsBioCal;
		updatePatientData.Ethnicity__c = strEthnicity;
		updatePatientData.Asthma__c = strAsthma;
		updatePatientData.Gender__c = strGender;
		updatePatientData.Date_of_Birth__c = dtmDateOfBirth;
		updatePatientData.COPD__c = strCOPD;
		updatePatientData.Height__c = numHeight;
		updatePatientData.Weight__c = numWeight;
		//updatePatientData.Site__c = strsite;
		
		update updatePatientData;
        }
        else
        {
        insertPatientData = new Patient_Data__c();
		
		insertPatientData.Patient_ID__c = strPatientId;
		insertPatientData.First_Name__c = strFirstName;
		insertPatientData.Last_Name__c = strLastName;
		insertPatientData.IsBioCal_Int__c = strIsBioCal;
		insertPatientData.Ethnicity__c = strEthnicity;
		insertPatientData.Asthma__c = strAsthma;
		insertPatientData.Gender__c = strGender;
		insertPatientData.Date_of_Birth__c = dtmDateOfBirth;
		insertPatientData.COPD__c = strCOPD;
		insertPatientData.Height__c = numHeight;
		insertPatientData.Weight__c = numWeight;
		//insertPatientData.Site__c = strsite;
		
		insert insertPatientData;
        }
        return insertPatientData;
    }
}

 And I am getting Invalid Type: wsLoad_NDD_Data.LoadPatientData on teh following code:

@isTest
private class wsLoad_NDD_DataTest {

    static testMethod void wsLoad_NDD_DataTest() {
        
                wsLoad_NDD_Data.LoadPatientData = new wsLoad_NDD_Data.LoadPatientData('123456', 'John', 'Smith', 'Yes', 'Caucasian', 'Yes', 'Male', System.today(), 'Yes', 12, 12);

}

 I figured this would be a breeze. What am I missing?

Best Answer chosen by Admin (Salesforce Developers) 
Saikishore Reddy AengareddySaikishore Reddy Aengareddy

Try this...static methods does not need object instantiation...

 

Patient_Data__c p = wsLoad_NDD_Data.LoadPatientData('123456', 'John', 'Smith', 'Yes', 'Caucasian', 'Yes', 'Male', System.today(), 'Yes', 12, 12);

All Answers

jblon1973jblon1973

Unfortunately, my code is structured a bit differently. This is where I am having the struggle. I read that post and as hard as I try I cannot duplicate the success.

 

I have tried by changing my test code to the following, and receive the same error:

wsLoad_NDD_Data.LoadPatientData pdtest = new wsLoad_NDD_Data.LoadPatientData(strPatientId = '123456', strFirstName = 'John', strLastName = 'Smith', strIsBioCal = 'Yes', strEthnicity = 'Caucasian', strAsthma = 'Yes', strGender = 'Male', dtmDateOfBirth = System.today(), strCOPD = 'Yes', numHeight = 12, numWeight = 12);

 

Saikishore Reddy AengareddySaikishore Reddy Aengareddy

Try this...

 

wsLoad_NDD_Data pdtest = new wsLoad_NDD_Data();


Patient_Data__c p = new Patient_Data__c();


p =pdtest.LoadPatientData(strPatientId = '123456', strFirstName = 'John', strLastName = 'Smith', strIsBioCal = 'Yes', strEthnicity = 'Caucasian', strAsthma = 'Yes', strGender = 'Male', dtmDateOfBirth = System.today(), strCOPD = 'Yes', numHeight = 12, numWeight = 12);

jblon1973jblon1973

I just tried that and received "Variable: strPatianetId does not exist". I experimented a bit by removing the variables to make it look like this:

wsLoad_NDD_Data pdtest = new wsLoad_NDD_Data();
        
        Patient_Data__c p = new Patient_Data__c();
        
        p = pdtest.LoadPatientData('123456', 'John', 'Smith', 'Yes', 'Caucasian', 'Yes', 'Male', System.today(), 'Yes', 12, 12);

 And now I am receiving:

"Save error: Method does not exist or incorrect signature: [wsLoad_NDD_Data].LoadPatientData(String, String, String, String, String, String, String, Date, String, Integer, Integer) wsLoad_NDD_DataTest.cls"

jblon1973jblon1973

And to make this more complex, I have related objects I will be adding.

 

Thank you so much for your help!!

jblon1973jblon1973

When pushing all of this to a sandbox I get the following error instead:

"Save error: Static methods cannot be invoked through an object instance: LoadPatientData(String, String, String, String, String, String, String, Date, String, Integer, Integer) wsLoad_NDD_DataTest.cls"

Saikishore Reddy AengareddySaikishore Reddy Aengareddy

Try this...static methods does not need object instantiation...

 

Patient_Data__c p = wsLoad_NDD_Data.LoadPatientData('123456', 'John', 'Smith', 'Yes', 'Caucasian', 'Yes', 'Male', System.today(), 'Yes', 12, 12);

This was selected as the best answer
jblon1973jblon1973

Thank you. You were a HUGE help!!!