You need to sign in to do that
Don't have an account?
jblon1973
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?
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
Look at this post... This will help you.
http://boards.developerforce.com/t5/Apex-Code-Development/Testing-APEX-Web-services/m-p/268557/highlight/true#M46798
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:
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);
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:
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"
And to make this more complex, I have related objects I will be adding.
Thank you so much for your help!!
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"
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);
Thank you. You were a HUGE help!!!