You need to sign in to do that
Don't have an account?
Robert Wambold 10
Please Help me solve "Illegal assignment from list to list"
Hello All,
I have a trigger where I want to be alerted when more than 10 EmailMessage records are inserted in an hour. I am unable to get past "Illegal assignment from list to list" error. I am at a loss what to do to solve.
Thanks for your help in advance!
Robert.
* Here's my code *
trigger CountEmailMessagesCreated1HourAgo on EmailMessage (after insert) { String NEW_RelatedToId; System.debug('Record Map: '+Trigger.newMap); DateTime OneHourAgo = System.Now().addHours(-1); System.debug('System.Now(): ' + System.Now()); System.debug('One Hour Ago: ' + OneHourAgo); List<String> EmlLst = new List<String>(); for(EmailMessage Eml : Trigger.new) { NEW_RelatedToId=Eml.RelatedToId; List<EmailMessage> EmlLst = [SELECT RelatedToId, COUNT(ID) FROM EmailMessage WHERE RelatedToId =:NEW_RelatedToId AND CreatedDate>=:OneHourAgo GROUP BY RelatedToId HAVING Count(Id) >10 ]; If (EmlLst.size() >0){ List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>(); Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); List<String> sendTo = new List<String>(); sendTo.add('SendToSomeone.@gmail.com' ); mail.setHtmlBody('Hello, <br/> This Case Id ' +NEW_RelatedToId +' has generated more than 10 in the last hour. <br/><br/> Thanks, <br/>Salesforce Admin'); mail.setSubject('Case EmailMessage Limit of 10 Exceeded'); mail.setToAddresses(sendTo); mails.add(mail); Messaging.sendEmail(mails); } } }
check this once.
For further reference, you can go through this too,
https://developer.salesforce.com/forums?id=906F0000000981XIAQ
Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.
Thanks.
Hello Abhishek,
Thanks for the links, but I am still struggling try to solve my issue.