You need to sign in to do that
Don't have an account?
Thabthimsaen 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();
}
}
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();
}
}
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
Please mark it as the Best If your queries are solved.
Thank You
All Answers
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
Please mark it as the Best If your queries are solved.
Thank You
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
Thank you very much for your help. The issue is fixed.
Bass