You need to sign in to do that
Don't have an account?
CageMMA
SendEmail failed. First exception on row 0; first error: SINGLE_EMAIL_LIMIT_EXCEEDED, null: []????
Hi I have no idea why am i getting this error message:
SendEmail failed. First exception on row 0; first error: SINGLE_EMAIL_LIMIT_EXCEEDED, null: []
trigger GeneralCaseAlertNotification on Case (after insert, after update) { if(RunTriggerOnceEmail.firstRun){ //Boolean used to send email only if valid conditions and email exists Boolean toMail = false; List<string> lstEmail = new List<string>(); Set<id> setCaseId= new Set<id>(); Set<id> setAccountId = new Set<id>(); Set<String> setEmail = new Set<String>(); String salesforceUrl = URL.getSalesforceBaseUrl().toExternalForm() + '/'; Map<Id, User> mapUnSubscribedUser = new Map<Id, User>([Select Email_Alert_Subscription__c , Id From User where Email_Alert_Subscription__c includes ('General CIQ Case Alert') And isActive = true]); for(Case objcase: trigger.new){ if(Trigger.IsInsert && objcase.Status == 'Escalated'){ setCaseId.add(objcase.id); setAccountId.add(objcase.AccountId); } if(Trigger.IsUpdate && trigger.oldMap.get(objcase.Id).Status != objcase.Status && (objcase.Status == 'Closed' || objcase.Status == 'Escalated')) { setCaseId.add(objcase.id); setAccountId.add(objcase.AccountId); } } Map<Id, List<AccountTeamMember>> mapATM = new Map<Id, List<AccountTeamMember>>(); for(Account a : [Select Id, (select user.email from AccountTeamMembers where TeamMemberRole IN('Account Manager', 'Lead Sales Executive', 'Regional Sales Executive', 'Team (Activity Alerts)')) from Account where Id In: setAccountId]) mapATM.put(a.Id, a.AccountTeamMembers); List<Messaging.SingleEmailMessage> lstMail = new List<Messaging.SingleEmailMessage>(); String strEmailBody = ''; String strCaseDetail = ''; for(Case objcased : [SELECT Id, CaseNumber, Type, Status, Origin, Subject, Priority, Description, Resolution__c, Action_Code__c, Resolution_Code__c, ID_Sharing_User_Names__c, Internal_Notes__c, ID_Sharing__c, Feature__c, Section__c, Contact.Id, Contact.Name, Contact.Phone, Contact.Email,ThreadID__c, Account.Id, Account.Name, Ownerid,CreatedBy.Alias, Owner.Name FROM Case Where Id IN: setCaseId AND RecordType.Name = 'Client Services - CIQ' AND CIQ_Escalate_To__c != 'Account Team']){ lstEmail = new list<string>(); setEmail = new Set<String>(); strCaseDetail = ''; //Collect Email Id from Account Team Member if(mapATM.ContainsKey(objcased.Accountid) && !mapATM.get(objcased.Accountid).isEmpty()) for(AccountTeamMember objAtm : mapATM.get(objcased.Accountid)) if(mapUnSubscribedUser.containsKey(objAtm.UserId)) setEmail.add(objAtm.user.email); if(!setEmail.isEmpty()){ if(!toMail) toMail = true; //Get Unique Email ids for(String s: setEmail) lstEmail.add(s); strEmailBody = 'This is a general case alert. However, you can reply to this e-mail and the Case Owner will be alerted.'+'<br/>'+ 'Please see below.'+'<br/>'+ 'Case Owner:' + objcased.Owner.Name + '<br/>'+ 'Case Detail:'+'<br/>'+ 'Type = ' + objcased.Type + '<br/>'+ 'Status = ' + objcased.Status + '<br/>'+ 'Origin = ' + objcased.Origin + '<br/>'+ 'Priority = ' + objcased.Priority +'<br/>'+ 'Client Info:'+'<br/>'+ 'Account Name = ' + '<a href=\'' + salesforceUrl + objcased.Accountid + '\'>'+ objcased.Account.Name + '<a/>'+ '<br/>'+ 'Contact Name = ' + '<a href=\'' + salesforceUrl + objcased.Contactid + '\'>'+ objcased.Contact.Name + '<a/>'+ '<br/>'+ 'E-mail = ' + objcased.Contact.Email +'<br/>'+ 'Phone = '+ objcased.Contact.Phone +'<br/>'+ 'General Product Information:'+'<br/>'+ 'Section = ' + objcased.Section__c +'<br/>'+ 'Feature = ' + objcased.Feature__c +'<br/>'+ 'Sharing? = ' + objcased.ID_Sharing__c +'<br/>'+ 'Sharing with = ' + objcased.ID_Sharing_User_Names__c+'<br/>'+ 'Description Information:'+'<br/>'+ 'Subject =' + objcased.Subject +'<br/>'+ 'Description = ' +objcased.Description +'<br/>'+ 'Resolution Details: Action=' + objcased.Action_Code__c+'<br/>'+ 'Resolution =' + objcased.Resolution__c+'<br/>'+ 'Internal Notes ='+ objcased.Internal_Notes__c +'<br/>'+ 'Case number = ' + objcased.CaseNumber +'<br/>'+ 'Thread Id : ' + objcased.ThreadID__c +'<br/>'+ 'Click on the link to access the case: '+ '<a href=\'' + salesforceUrl + objcased.Id + '\'>'+ objcased.CaseNumber + '<a/>'+ '<br/>'+ strCaseDetail; OrgWideEmailAddress owa = [select id, DisplayName, Address from OrgWideEmailAddress where displayName='S&P Capital IQ Client Services' limit 1]; //New instance of a single email message Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); mail.setToAddresses(lstEmail); mail.setOrgWideEmailAddressId(owa.id); mail.setSaveAsActivity(true); mail.setSubject('General Case Alert, Case Number:' + objcased.CaseNumber + ', ' + objcased.Account.Name+', '+ objcased.Contact.Name); mail.setHtmlBody(strEmailBody); lstMail.add(mail); try{ //Send Email if(toMail){ if(objcased.CreatedBy.Alias!='Merge' || objcased.CreatedBy.Alias<>'Merge' ){ Messaging.sendEmail(lstMail); } } } catch(exception objEx){ Trigger.new[0].addError('Some unexpected error occured. Please call your system admin if error persists : '+objEx.getMessage()); } RunTriggerOnceEmail.firstRun=false; } } } RunTriggerOnceEmail.firstRun=false; }
Someone help...I do not get this in sandbox. only when i pushed it out to prod.
thanks
There are 2 thing u need to take care of
1)U r using SingleEmailMessage
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
In place of that try MassEmailMessage
Messaging.MassEmailMessage mail = new Messaging.MassEmailMessage();
2) As i look into u r code
U r Messaging.sendEmail(lstMail); is inside for loop "for(Case objcased : [SELECT Id, CaseNu....." that is not a good pratice try to make a list of array of a list & try to use Messaging.sendEmail(lstMail); function out side the for loop
Is this what you mean:
How would I test this to see what limits am i hitting? What is the limit for mass emailing?
One more thing my template emails balnk?