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
Matan AlonMatan Alon 

Calling a webservice method from apex test class

I have a simple webservice method that updates Account Status from a custom Button in the Opportunity page:

Global class Backoffice {
    WebService static Integer  GenerateBackofficeTask(id  opId) {  
        Opportunity op = [SELECT AccountId from Opportunity WHERE Id =: opId];
        if(op.AccountId!=null)
            {
                Account ac = [SELECT Id from Account WHERE Id =: op.AccountId];
                ac.Type = 'Customer';
                update ac;
            }

    return 1;
    }   
}




Here the Test class i wrote:

@isTest
public  class BackOfficeTest {
    static testMethod void TestMyContractWebService() {

   Integer x = 0;  
    Account ac = new Account(Name='testAccount1');
    insert ac ;


    Opportunity op = new Opportunity(Name='testOpportunity1',AccountId=ac.Id,CloseDate =date.parse('12/12/2014'),StageName='Evaluation');
    insert op ;
    system.debug(op.AccountId);

      x= Backoffice.GenerateBackofficeTask(op.Id); 
    }
}


I don't know why I'm getting the following error:
Method does not exist or incorrect signature: Backoffice.GenerateBackofficeTask(Id)

Please help me this that - I tried to find the reason with no success

Thanks in advance,
Matan.
Nilesh Jagtap (NJ)Nilesh Jagtap (NJ)
Hi Matan,

Please refer https://www.salesforce.com/us/developer/docs/apexcode/Content/apex_callouts_wsdl2apex_testing.htm to write test class for webservice.

Thanks,
N.J