0

Hi I create List method with many parameters required than later be called in another void method sendRenewalReminder but I get this error

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

Can someone help me to understand how this works actually in apex?

public class automatedCommunication{


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

    //Template for ID
    public EmailTemplate ExpiringContractID = [SELECT Id, Name, Description, Subject FROM EmailTemplate WHERE Name =: 'Contract renewal notice ID' LIMIT 1];
    public EmailTemplate DueInvoiceID = [SELECT Id, Name, Description, Subject FROM EmailTemplate WHERE Name =: 'Invoice due reminders ID' LIMIT 1];

    public Id emailtemplate;
    public String templateDescription;              // The template description will be assigned to the Task Subject of the task
    public String templateSubject;
    public Id invPDFattachmemt{get;set;}
    public Attachment attach{get;set;}
    public EmailTemplate template;
    public List<Invoice__c> linv;

    public String senderName = 'xxx';
    public String defaultReplyEmailID = '[email protected]';
    public String defaultReplyEmailPH = '[email protected]';
    public String defaultReplyEmailMX = '[email protected]';

    public String expiredConQuery ='SELECT Id, AccountId, Account.AccountManager__r.Email, Account.AccountManager__r.isActive, Account.Owner.Email, Account.Owner.isActive, Account.Contractsigneduntil__c, Account.Due_date_of_last_open_invoice__c FROM Contact WHERE Id in: licontact';

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

    String ReplyToEmail;

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

    mail.setTemplateId(templateName);  
    mail.setOrgWideEmailAddressId(orgEmailAddress);
    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); 
    mails.add(mail);

    return mails;      
}

    public void sendRenewalReminder(){

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

        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 != 'ID') {

                    template = DueInvoiceID; 
                } 


                emailtemplate = template.Id;

                createEmailMessage(emailtemplate, orgWideMail, 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(createEmailMessage.mail);
            }

            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

1

Your types simply don't match up, as the error is indicating.

You declare:

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

You call:

createEmailMessage(
   emailtemplate,            // Id - but note the confusion with the built-in class name; Apex is case-insensitive
   orgWideMail,              // List<OrgWideEmailAddress> - this type is wrong.
   cont.Id,                  // Id
   cont.AccountId,           // Id
   cont.Account.AccountManager__r.Email, // String - this type is wrong in the method declaration.
   cont.Account.AccountManager__r.isActive, // Boolean
   cont.Account.Owner.Email, // String - this type is wrong in the method declaration
   cont.Account.Owner.isActive, // Boolean
   cont.Account.AccountCountry__c // String
); 

You'll need to make changes to both your calling and called methods to correct these errors.

2
  • Hi David, I have edited both but seems unable to fix the List<OrgWideEmailAddress> part, could you help? and actually I need to return only one single message from createEmailMessage function and the return value should be added into List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>(); inside ``sendRenewalReminder``` is it possible to achieve this? Nov 6, 2019 at 5:09
  • Hi David I have fixed everything, nevermind with my comments above. thanks a lot! Nov 6, 2019 at 7:30

You must log in to answer this question.

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