You need to sign in to do that
Don't have an account?
Please Solve this problem:- System.LimitException: Too many Email Invocations: 1
req.setMethod('POST'); req.setHeader('Content-Type', 'application/x-www-form-urlencoded'); SendmailUtils.Emailtemplate emailtmp=new SendmailUtils.EmailTemplate(); emailtmp.emailTemplate=bdy.escapeHtml4(); if(Contactlists.size() == 0) { ReturnContactList([SELECT Name,FirstName,LastName,description,Email,Title,Company,ID,phone FROM Lead where email=:Emailcon LIMIT 1]); } string isQue='0'; req.setBody('AUCode='+aucode+'&SOrgID='+ocode+'&Subject='+sbj+'&To='+too+'+&Bcc=&contacts='+JSON.serialize(Contactlists)+'&Body='+JSON.serialize(emailtmp)+'&contents='+JSON.serialize(contentCategoryIDs)+'&IsQueue='+isQue); try { res = http.send(req); if (res.getBody() != null) { if(isQue=='0') { List<SendmailUtils.EmailTemplateListData> emailLists=new List<SendmailUtils.EmailTemplateListData>(); emailLists=(List<SendmailUtils.EmailTemplateListData>)json.deserialize(res.getbody(),List<SendmailUtils.EmailTemplateListData>.class); String userName = UserInfo.getUserName(); User activeUser = [Select Email From User where Username = : userName limit 1]; String userEmail = activeUser.Email; for(SendmailUtils.EmailTemplateListData emailData: emailLists) { if(emailData.To != null || emailData.To != '') { Messaging.SingleEmailMessage emails = new Messaging.SingleEmailMessage(); List<String> sendTo = new List<String>(); sendTo.add(emailData.To); // System.debug ( 'emailData.To' +emailData.To); emails.setToAddresses(sendTo); emails.setSubject(emailData.Subject); if(emailData.Body!=null) emailData.Body = emailData.Body.unescapeHtml4(); emails.setHtmlBody(emailData.Body); emails.setReplyTo(userEmail); -----------: Error shows in this below line:------ Messaging.SendEmailResult [] resSentEmail= Messaging.SendEmail(new Messaging.SingleEmailMessage[] {emails}); for ( Messaging.sendEmailResult result : resSentEmail ) { if ( !resSentEmail[0].isSuccess () ) { // System.debug ( 'result' +result ); } }
You can only invoke 10 Send Emails per Context. That is governor limit. You are hitting 11 emails and its bombing.
To fix this, you can create a Batch Apex Class that your Schedule Apex invokes. Move the Send Email logic inside your Batch Apex class and scope the batch so that is only processes 10 contacts at a time.
http://forceguru.blogspot.in/2011/03/how-to-send-more-than-10-e-mails.html
http://help.salesforce.com/apex/HTViewSolution?id=000003864&language=en_US (http://help.salesforce.com/apex/HTViewSolution?id=000003864&language=en_US)
Thanks
Swaraj