【问题标题】:How to resolve "Method does not exist or incorrect signature" error如何解决“方法不存在或签名不正确”错误
【发布时间】:2021-12-29 03:29:59
【问题描述】:

我有以下代码:

public class MergeDuplicatesController {
    @AuraEnabled
    public static List<Contact> findContacts(String searchValue, Boolean selected, Boolean  isPrime, Integer length) {
        searchValue = '%'+searchValue+'%';
        //List<ContactWrapper> ContactList = new List<ContactWrapper>();
        //integer i = 1;
        List<Contact> conList = [SELECT Name, Account.Name FROM Contact WHERE Name LIKE : searchValue];
        for(Contact con : conList){
            ContactWrapper wr = new ContactWrapper();
            wr.isPrime = isPrime;
            wr.selected = selected;
            conList.add(wr);            
        }
        return conList;
    }   
    public class ContactWrapper{
        @AuraEnabled
        public Boolean selected;
        @AuraEnabled
        public Boolean isPrime;
        @AuraEnabled
        public Contact con;
    }
}

但它抛出了错误:

方法不存在或签名不正确:

void add(MergeDuplicatesController.ContactWrapper)

来自List&lt;Contact&gt;类型

我该如何解决?

【问题讨论】:

    标签: salesforce apex


    【解决方案1】:

    您定义了List&lt;Contact&gt; conList。联系人列表。它只接受Contact 类的对象。您不能将ContactWrapper 添加到此列表中,因为它不是联系人,它不会扩展(继承自)联系人...

    可能需要这样的东西

    public static List<ContactWrapper> findContacts(String searchValue, Boolean selected, Boolean  isPrime, Integer length) {
            searchValue = '%'+searchValue+'%';
            List<ContactWrapper> ret = new List<ContactWrapper>();
            List<Contact> conList = [SELECT Name, Account.Name FROM Contact WHERE Name LIKE : searchValue];
            for(Contact con : conList){
                ContactWrapper wr = new ContactWrapper();
                wr.con = con;
                wr.isPrime = isPrime;
                wr.selected = selected;
                ret.add(wr);            
            }
            return ret ;
        } 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-20
      • 1970-01-01
      • 2022-11-05
      • 1970-01-01
      • 2011-08-29
      相关资源
      最近更新 更多