You need to sign in to do that
Don't have an account?
chikku
Now I have developed static, I need in dynamic.
How send email dynamic based on Contact email id
- I have created a Vf page and apex to send PDF attachments in email.
- I have object Apple__c with Lookup Contact
- When I create a new Apple record and Particular contact with Email, then email should send to the contact which I have selected.
Now I have developed static, I need in dynamic.
public class sendAnEmail { @InvocableMethod(label='Test' description='sends an email') public static void sendEmailWithAttachment(List<id> listofQuoteHeader) { List<Contact> Con = [SELECT Id, Email FROM Contact ]; for(Id QuoteHeaderid :listofQuoteHeader) { PageReference pref= page.PDFGEN; pref.getParameters().put('id',(Id)QuoteHeaderid); pref.setRedirect(true); Attachment attachment = new Attachment(); Blob b=pref.getContentAsPDF(); attachment.Body = b; attachment.Name = Datetime.now().format('yyyy-MM-dd HH:mm') + ' ' + 'Quote' + '.pdf'; attachment.IsPrivate = false; attachment.ParentId = QuoteHeaderid; insert attachment; Messaging.SingleEmailMessage semail= new Messaging.SingleEmailMessage(); Messaging.EmailFileAttachment attach= new Messaging.EmailFileAttachment(); attach.setBody(pref.getContentAsPDF()); semail.setSubject('Quote Issued'); String[] emailIds= new String[]{'abc@gmail.com'}; // I need this part has dynamic based on contact email id i choosed semail.setToAddresses(emailIds); semail.setPlainTextBody('Please find the attached quote details'); semail.setFileAttachments(new Messaging.EmailFileAttachment[]{attach}); Messaging.sendEmail(new Messaging.SingleEmailMessage[]{semail}); } } }
This is been already addressed on following questions posted from your end:
https://trailblazers.salesforce.com/answers?id=9064S000000DrztQAC
https://developer.salesforce.com/forums/?id=9062I000000DIpp
Please mark as Best Answer so that it can help others in the future.
Thanks.