I have List as a parameter of the method but get the error when saving the class

Error: Compile Error: Method does not exist or incorrect signature: void createEmailMessage(Id, OrgWideEmailAddress, Id, Id, String, Boolean, String, Boolean, String) from the type automatedCommunication at line 138 column 24

public List<OrgWideEmailAddress> orgWideMail = [SELECT Id FROM OrgWideEmailAddress];

public Messaging.SingleEmailMessage createEmailMessage(Id templateName, List<OrgWideEmailAddress> orgWideEmail, Id targetObjectId, Id whatId, String accountManagerEmail, boolean accountManagerStatus, String accountOwnerEmail, boolean accountOwnerStatus, String country ){

    String ReplyToEmail;

    Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();


    IF(accountManagerEmail <> null && accountManagerStatus == TRUE)
        ReplyToEmail = accountManagerEmail;
    ELSE IF(accountOwnerEmail <> null && accountOwnerStatus == TRUE)
        ReplyToEmail = accountOwnerEmail;
    ELSE IF(country == 'ID')
        ReplyToEmail = defaultReplyEmailID; 
    ELSE IF(country == 'PH')
        ReplyToEmail = defaultReplyEmailPH; 
        ReplyToEmail = defaultReplyEmailMX;      

    return mail;      

and call it in below method

 public void sendRenewalReminder(){

/**** Set Template ****/

        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
        List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
        Set<Id> ids = new Set<Id>();

/**** Set filters and conditions (recipients and criteria -> To:, When?, who?, why?) ****/
        List<Contact> licontact = [SELECT Id FROM Contact
                            WHERE ContactForContracts__c = TRUE     // only contacts that are marked to receive contract info
                            AND Email <> ''
                            AND Account.ExcludeFromAutomatedSendouts__c = FALSE                 // Checkbox on account to exclude Account from sendouts
                            AND Account.Contractsigneduntil__c =: system.today() + 35           
                               (Account.AccountCountry__c = 'ID'
                            OR  Account.AccountCountry__c = 'PH'
                            OR  Account.AccountCountry__c = 'MX') 
                            AND Account.TypeOfCompany__c = 'Agent / Broker' 
                            AND (Account.LastRenewalNoticeDate__c <: system.today() OR Account.LastRenewalNoticeDate__c =: null)];  // avoids multiple sendouts in case the method is called several times on the same day
        system.debug('aaa' + licontact.size());

/**** Start process ****/

        IF(licontact.size() >0){

            /**** Set parameters ****/
            List<Contact> contacts = new List<Contact>();
            contacts = Database.query(expiredConQuery);

            FOR(Contact cont : contacts){
            List<Account> accounts = [SELECT LastRenewalNoticeDate__c FROM Account WHERE Id in: ids];

            /**** Create emails ****/

            FOR(Contact cont : contacts){

                if(cont.Account.AccountCountry__c == 'ID') {

                    template = ExpiringContractID;

                if(cont.Account.AccountCountry__c == 'MX') {

                    template = ExpiringContractMX; 

                if(cont.Account.AccountCountry__c == 'PH'){

                    template = ExpiringContractPH;

                emailtemplate = template.Id;

                mail = createEmailMessage(emailtemplate, orgWideMail[0], cont.Id, cont.AccountId, cont.Account.AccountManager__r.Email, cont.Account.AccountManager__r.isActive, cont.Account.Owner.Email, cont.Account.Owner.isActive, cont.Account.AccountCountry__c); 


                if(Integer.valueof(Limits.getQueries()) >= 40){


        /**** Send emails ****/
            IF(mails.size() >0){
                Messaging.sendEmail(mails, false);

                /***** updates Account date of last sendout to avoid multiple sendouts ****/
                FOR(Account acc : accounts){
                    acc.LastRenewalNoticeDate__c = system.today();

                update accounts;

As the error suggests, your issue is on the line where you are calling the method.

// orgWideMail[0] is an instance of OrgWideEmail
mail = createEmailMessage(emailtemplate, orgWideMail[0], .....); 

You are passing a single record of type OrgWideEmailAddress when you are calling the method, whereas your method is declared to accept a List<OrgWideEmailAddress> as:

// accepts List<Id>
createEmailMessage(Id templateName, List<Id> orgWideEmail, ....)

You will need to either pass a List<OrgWideEmailAddress> or change the method argument to accept a single OrgWideEmailAddress record.

  • I have edited my code but getting this error Error: Compile Error: Method does not exist or incorrect signature: void setOrgWideEmailAddressId(List<OrgWideEmailAddress>) from the type Messaging.SingleEmailMessage at line 62 column 10 ? Nov 8 '19 at 3:58
  • Because that's not the correct arguments that the method expects. I will really recommend that you go through the documentation to get more clarity and be able to utilize the correct methods here.
    – Jayant Das
    Nov 8 '19 at 14:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.