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
Arav SundarArav Sundar 

Need help Test class for webservice

Hi, 

Need help on the below things 

global class OpprtunityWEbservice2{
   
    webService static String test1(String year,String accId, String mheCourseId, String term, String stage, String name ,Boolean productInUseUpdate,String creationSourceId,String contactId,String productId, String pricebookEntryId,Double unitPrice, String targetedCreationSourceId, Boolean restrictOppLineCreation){
        String newOptyId;
      try{
        test2 o = new test2(Name=name,year__c=year,accountId=accId,MHE_Course__c=mheCourseId,Term__c=term,StageName=stage,CloseDate=System.Today(),Product_in_Use_Update__c=productInUseUpdate,Creation_Source_ID__c=creationSourceId);
        insert o;
        newOptyId =''+o.id;
         
        test 3 oc=new test 3(Name='test45',Contact_Name__c=contactId,Opportunity__c=newOptyId );
        insert oc;
        
        if(restrictOppLineCreation == false){
            System.debug('restrict oppline creation ::'+restrictOppLineCreation);
            test4 ol=new test4(OpportunityId=newOptyId ,Quantity=1,UnitPrice=unitPrice,PricebookEntryId=pricebookEntryId,Creation_Source_ID__c=targetedCreationSourceId);
            insert ol;
           }else{
               System.debug('restrict oppline creation*** ::'+restrictOppLineCreation);
           }
        return newOptyId;
      }catch(Exception e){
        return e.getmessage();
    }
    }
   
}


ANd the test class i am trying is below pls help 

@isTest Class Test_webservice{

private Static TestMethod void test1(){
   
   OpprtunityWEbservice2.test1 test = new OpprtunityWEbservice2.test1();



Getting an error (Invalid type: OpprtunityWEbservice2.test1 at line 101 column 65    


ManojjenaManojjena
Hi Arav,

You need to call the method with class name as it is a static method .Here one thing you need to follow like you need to create testdata to pass the parameter .
Like create a account record then pass the method .Same you need to pass all parameter in the method .

For  simple example I have create a test class please modifyand try to implement it any issue let me know .
 
@isTest
private class OpprtunityWEbservice2Test{
    private static testmethod void unitTest(){
      //Here you need to create test record .
       String year='2015';
      OpprtunityWEbservice2.test1(year);
    }
 }

Let me know if it helps !!
Thanks 
Manoj