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
Thabthimsaen WuttisakThabthimsaen Wuttisak 

Error Message Method does not exist or incorrect signature

Hi Everyone,
I am a newbie for creating an apex class. I create an Apex class to update a status. Then, I tried to create a test class. However, I received the below error message.

"Method does not exist or incorrect signature: void Updatestatus(ConsumableSample__c) from the type UpdateStatusController"

Could you please advise?

My Apex Class:

global without sharing class UpdateStatusController {
    @AuraEnabled
    global static Boolean Updatestatus(Id sampleid){
        try{
        
            ConsumableSample__c cs= [Select Id,Name,Process_Status__c from ConsumableSample__c where Id=:sampleid];
            cs.Process_Status__c = 'Cancel';
            update cs; 
            return true;
        }
        catch(Exception e){
            return false;
        }
    }
}


My Apex Test Class:

@isTest
public class UpdateStatusControllerTest {
  static testMethod void test1() {
      Date sDate = Date.newInstance(Date.today().Year(), 1, 1);
        Date eDate = Date.newInstance(Date.today().Year() + 1, 12, 31);
        Integer cnt = sDate.daysBetween(eDate);
        List<OlympusCalendar__c> ocList = new List<OlympusCalendar__c>();
        String cc = 'Singapore';
        for (Integer i=0; i<cnt; i++) {
            ocList.add(new OlympusCalendar__c(Date__c=sDate.addDays(i),Country__c = cc));
        }
        insert ocList;
        
        Date nowWD = Date.today();
        Account hospital = new Account();
        hospital.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and Name='Hospital'].id;
        hospital.Name = '华佗扁鹊孙思邈';
        hospital.Adress__c = '医界仙葩,圣手仁心!';
        insert hospital;
        
        List<Account> strategicDep = [SELECT ID, Name FROM Account WHERE parentId = :hospital.Id AND recordType.Name = 'GI-Dept'];        
        
        Account dep = new Account();
        dep.recordtypeId = [Select Id FROM RecordType WHERE IsActive = true and SobjectType = 'Account' and Name = 'Gastoro Intestin'].id;
        dep.Name = '救济丸';
        dep.ParentId = strategicDep[0].Id;
        dep.Department_Class__c = strategicDep[0].Id;
        dep.Hospital__c = hospital.Id;
        insert dep;

        ConsumableSample__c request = new ConsumableSample__c(Hospital__c = hospital.Id,
        Expect_Arrive_Date__c = Date.today(),Expect_Use_Date__c = Date.today(),
        PIC__c = Userinfo.getUserId());
        insert new list<ConsumableSample__c> { request };

        test.startTest();
        UpdateStatusController.Updatestatus(request);
        test.stopTest();
  }
}
 
Best Answer chosen by Thabthimsaen Wuttisak
Suraj Tripathi 47Suraj Tripathi 47

Hi Thabthimsaen,

Please find the solution.

You are passing Id in the method "Updatestatus" but you are sending Object from test class to this method.

Please correct It Like the below

        test.startTest();
        UpdateStatusController.Updatestatus(request.id);
        test.stopTest();

Please mark it as the Best If your queries are solved.

Thank You

All Answers

Suraj Tripathi 47Suraj Tripathi 47

Hi Thabthimsaen,

Please find the solution.

You are passing Id in the method "Updatestatus" but you are sending Object from test class to this method.

Please correct It Like the below

        test.startTest();
        UpdateStatusController.Updatestatus(request.id);
        test.stopTest();

Please mark it as the Best If your queries are solved.

Thank You

This was selected as the best answer
PriyaPriya (Salesforce Developers) 

Hi Thabthimsaen,

 

In the 3rd line, in your apex class, you are passing the ID as parameter in the method 'Updatestatus'.

But while calling that method in your test class, you are not passing the ID and hence the error. 

so try below :- 

UpdateStatusController.Updatestatus(request.id);

If the above explanation helps, please mark it as best answer.

regards,

Priya Ranjan

Thabthimsaen WuttisakThabthimsaen Wuttisak
Hi @Priya and @Suraj,

Thank you very much for your help. The issue is fixed.

Bass