while am executing this code am getting this error as single email limit exceeded. An Apex error occurred: System.EmailException: SendEmail failed. First exception on row 0; first error: SINGLE_EMAIL_LIMIT_EXCEEDED, Email limit exceeded: [] code:
public class Idfattachment
{
@InvocableMethod
public static void Idfattach(List<Id> InventionDisclosure)
{
IDF_Email__c settings = IDF_Email__c.getInstance('EmailConfig');
String status= settings.status__c;
String tosub = settings.subject__c;
String toemail = settings.Email__c;
Boolean taction = settings.Mail_ON_OFF__c;
if(taction)
{
List<Messaging.SingleEmailMessage> myListofMails = NEW List<Messaging.SingleEmailMessage>();
Map<string,List<ContentDocumentLink>> MapIDFsDocLink = NEW Map<string,List<ContentDocumentLink>>();
set<id> ConLinkIDset = New set<id>();
list<id> idfid = New list<id>();
List<ContentDocumentLink> lstContentDocumentLinks = [SELECT ContentDocumentId,Id,LinkedEntityId
FROM ContentDocumentLink WHERE LinkedEntityId IN: InventionDisclosure];
for(ContentDocumentLink ConDocLink : lstContentDocumentLinks)
{
ConLinkIDset.add(ConDocLink.ContentDocumentId);
List<ContentDocumentLink> temp = MapIDFsDocLink.get(ConDocLink.LinkedEntityId);
if(temp == null)
{
MapIDFsDocLink.put(ConDocLink.LinkedEntityId, new List<ContentDocumentLink>{ConDocLink});
}
else
{
temp.add(ConDocLink);
}
}
Map<string,List<ContentVersion>> MapLinksDocuments = NEW Map<string,List<ContentVersion>>();
List<ID> ConLinkIDSList = NEW List<ID>(ConLinkIDset);
List<ContentVersion> documents= [
SELECT Id, Title,PathOnClient,VersionData,isLatest,ContentDocumentId
FROM ContentVersion
WHERE isLatest = true AND ContentDocumentId IN:ConLinkIDSList
];
for(ContentVersion ConDoc : documents)
{
List<ContentVersion> temp = MapLinksDocuments.get(ConDoc.ContentDocumentId);
if(temp == null)
{
MapLinksDocuments.put(ConDoc.ContentDocumentId, new List<ContentVersion>{ConDoc});
}
else
{
temp.add(ConDoc);
}
}
List<Invention_Disclosure_New__c> idf1 = [Select Id,Title__c,Disclosure_Status__c from Invention_Disclosure_New__c where Id in : InventionDisclosure];
for(Invention_Disclosure_New__c idf : idf1)
{
if(idf.Disclosure_Status__c == status)
{
Id newDocLink = idf.Id;
if(MapIDFsDocLink.containsKey(idf.id))
{
set<ID> lstDocId = new set<ID>();
List<ContentDocumentLink> lstContentDocumentLinks1 =MapIDFsDocLink.get(idf.id);
for(ContentDocumentLink docit : lstContentDocumentLinks1)
{
lstDocId.add(docit.ContentDocumentId);
}
List<Messaging.EmailFileAttachment> attachments = new List<Messaging.EmailFileAttachment>{};
List<ContentVersion> documents1= NEW List<ContentVersion>();
for(id ids : lstDocId)
{
if(MapLinksDocuments.containsKey(ids))
{
List<ContentVersion> documentslist = MapLinksDocuments.get(ids);
documents1.addall(documentslist);
}
}
Messaging.SingleEmailMessage semail = new Messaging.SingleEmailMessage();
for (ContentVersion document: documents1)
{
Messaging.EmailFileAttachment attachment = new Messaging.EmailFileAttachment();
attachment.setBody(document.VersionData);
attachment.setFileName(document.PathOnClient);
attachments.add(attachment);
}
semail.setSubject(tosub);
string query ='SELECT Id,'+toemail+' FROM Invention_Disclosure_New__c WHERE Id =:newDocLink';
List<Invention_Disclosure_New__c > sobjList = Database.query(query);
String[] sendTo = new String[]{};
Set<string> fieldApis = New Set<string>();
List<String> lstAlpha = toemail.split(',');
if(lstAlpha.size()>0)
for(string s:lstAlpha)
{
fieldApis.add(s);
}
for(Invention_Disclosure_New__c tmpUser:sobjList)
{
if(fieldApis.contains('PPA_EmailId__c'))
if(tmpUser.PPA_EmailId__c!=null && tmpUser.PPA_EmailId__c!='')
sendTo.add(tmpUser.PPA_EmailId__c);
system.debug('PPA email:'+sendTo);
if(fieldApis.contains('Inventor_Email_Id__c'))
if(tmpUser.Inventor_Email_Id__c!=null && tmpUser.Inventor_Email_Id__c!='')
sendTo.add(tmpUser.Inventor_Email_Id__c);
system.debug('Inventor email:'+sendTo);
}
semail.setToAddresses(sendTo);
system.debug(semail);
String messageBody = '<html><body>Hi,New Invention Disclosure entitled '+idf.Title__c +',has been submitted for review.Please refer the attached document for the complete information of the submitted disclosure.</body></html>';
semail.setHtmlBody(messageBody);
semail.setFileAttachments(attachments);
if(attachments.size() > 0)
{
myListofMails.add(semail);
}
}
}
}
if(myListofMails.size()>0)
{
Messaging.sendEmail(myListofMails);
}
}
}
}
System.debug('List Size '+ idf1.size())
just after line 51 query. check logs then.System.debug('myListofMails'+ myListofMails.size());
beforeMessaging.sendEmail(myListofMails);
Line 121.