如何在我的简单测试类中发现错误的原因?
这是我检索双列表框的字段的Aura方法。
@AuraEnabled
public static List <String> getProperties(sObject objObject, string sFieldAPI) {
List < String > lstOptions = new list < String > ();
Schema.sObjectType objType = objObject.getSObjectType();
Schema.DescribeSObjectResult objDescribe = objType.getDescribe();
map <String, Schema.SObjectField> fieldMap = objDescribe.fields.getMap();
list < Schema.PicklistEntry > values =fieldMap.get(sFieldAPI).getDescribe().getPickListValues();
for (Schema.PicklistEntry a: values) {
lstOptions.add(a.getValue());
}
lstOptions.sort();
return lstOptions;
}
这是我遇到错误的测试类。
testMethod static void testGetProperties(){
setupInsertData();
Test.startTest();
List<String> Prop = MessageTypeController.getProperties('isArray');
System.debug('Test Category'+Prop);
if(Prop!=null){
System.assertEquals(Prop!=null,true);
}else{
System.assertEquals(Prop==null,true);
}
Test.stopTest();
}
错误的文本是:
“方法不存在或不正确签名:void getProperties(string)”
This is my aura method to retrieve fields for dual list box.
@AuraEnabled
public static List <String> getProperties(sObject objObject, string sFieldAPI) {
List < String > lstOptions = new list < String > ();
Schema.sObjectType objType = objObject.getSObjectType();
Schema.DescribeSObjectResult objDescribe = objType.getDescribe();
map <String, Schema.SObjectField> fieldMap = objDescribe.fields.getMap();
list < Schema.PicklistEntry > values =fieldMap.get(sFieldAPI).getDescribe().getPickListValues();
for (Schema.PicklistEntry a: values) {
lstOptions.add(a.getValue());
}
lstOptions.sort();
return lstOptions;
}
And this is the test class where I'm getting error.
testMethod static void testGetProperties(){
setupInsertData();
Test.startTest();
List<String> Prop = MessageTypeController.getProperties('isArray');
System.debug('Test Category'+Prop);
if(Prop!=null){
System.assertEquals(Prop!=null,true);
}else{
System.assertEquals(Prop==null,true);
}
Test.stopTest();
}
The text of the error is:
"Method does not exist or incorrect signature: void getProperties(String)"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您/您的同事定义
getProperties(sobject objobject,string sfieldapi)
,但您正在尝试使用getProperties('isArray'')
。没有1个参数的方法(至少在您粘贴的代码段中没有)。您可能想用类似
You / your colleague defined
getProperties(sObject objObject, string sFieldAPI)
but you're trying to call it withgetProperties('isArray')
. There's no method with 1 parameter (at least not in the code snippet you pasted).You probably want to call it with something like
现在,它正在奏效:
With this now it's working: