function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Kunal Purohit 4Kunal Purohit 4 

Method does not exist or incorrect signature: void setHtmlBody(String, Decimal) from the type Messaging.SingleEmailMessage

I am trying to send mail through Batch Apex. But it shows following Error.

Method does not exist or incorrect signature: void setHtmlBody(String, Decimal) from the type Messaging.SingleEmailMessage

batch Apex Class

public class EmailBatch implements database.Batchable<sobject>,Schedulable{
public decimal count=0;
    public void execute(Schedulablecontext sc)
    {
        EmailBatch eb=new EmailBatch();
    database.executeBatch(eb);
    }
    
    public database.QueryLocator start(database.BatchableContext bc)
    {
        string query='select Name,Journal_Email_Address__c,Total_Published_Paper__c from Account';
        return database.getQueryLocator(query);
    }
    
    public void execute(database.BatchableContext bc,list<Account> acc)
    {
        list<Account> alist=new list<Account>();
        for(Account a:acc)
        {
            count=count+a.Total_Published_Paper__c;
        }
        list<Messaging.SingleEmailMessage> mlist=new list<Messaging.SingleEmailMessage>();
        messaging.SingleEmailMessage email=new messaging.SingleEmailMessage();
        email.setSubject('Welcome');
        email.setHtmlBody('Total Paper Published is',+count);
        string[] to=new string[]{'kunalpurohit7@gmail.com'};
            email.setToAddresses(to);
        mlist.add(email);
        messaging.SendEmail(mlist);
        system.debug('Mail sent Successfully');
    }        
    public void finish(database.BatchableContext bc)
    {
system.debug('Email Sent');        
    }
}
Abhishek BansalAbhishek Bansal
Hi Kunal,

setHtmlBody acacepts only one parameter i.e. String so please change the line email.setHtmlBody('Total Paper Published is',+count); -> email.setHtmlBody('Total Paper Published is');
You can find the details of all the methods for the Messaging.SingleEmailMessage class in the below link:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_email_outbound_single.htm

Please close this question once you get the solution by choosing Best Answer so that it will help others in future. Do not leave your questions as Unsolved.

Thanks,
Abhishek Bansal.
Abhishek BansalAbhishek Bansal
Hi Kunal,

Did you get the solution that you were looking. Please make a practice to close your questions by choosing the best answer so that it can help others in future.
Let me know if you need any more help on this question.

Thanks,
Abhishek Bansal.