0

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();

    mail.setTemplateId(templateName);  
    mail.setOrgWideEmailAddressId(orgWideEmail[0]);
    mail.setTargetObjectId(targetObjectId); 
    mail.setWhatId(whatId);

    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; 
    ELSE
        ReplyToEmail = defaultReplyEmailMX;      
    mail.setReplyTo(ReplyToEmail); 

    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           
                            AND 
                               (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){
                ids.add(cont.Account.Id);
            }
            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); 

                mails.add(mail);

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

            system.debug(mails.size());
            system.debug(mails);

        /**** 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;
            }
        }
    }

1 Answer 1

2

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.

2
  • 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 ? Commented Nov 8, 2019 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
    Commented Nov 8, 2019 at 14:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .