You need to sign in to do that
Don't have an account?
Trigger - Mass email to Account with related records grouped
Fairly new to dev/apex. Just looking for some advice on how to start/structure my trigger as I'm struggling to get it started.
We want to send emails when Sales Invoices are overdue, to an email address on the related Account (related via lookup from invoice to account). My first thought was to create the trigger from the Account, but can I access the records related via the lookup on Sales Invoice? I couldn't get the SOQL statement working, so thought to do it from Sales Invoice, but that makes no sense as I need to group the Sales Invoices together where there are more than one overdue for each account, which happens more than not.
Any sugegstions greatly appreciated!
BATCH - the best option
This is a better use case to use batch and collections (our friends). Creat batch on the child, in this case Sales Invoice. Collect them in map<Id, List<Sales Invoice>> where Key is AccoutId and Value is List of all invoices that are overdue.
Before sending mass email consider Salesforce Email limitation( sending from salesforce) . you may have big chance to end up with Limit exceeded exception. design the trigger or Batch job according to this.
Thanks
karthik