You need to sign in to do that
Don't have an account?
chikku
Need to display related filed in pdf attachment in vf page
I have Application__c with Look Contact, I need to show Contact name and Application Name in Pdf attachment as dynamic.
public class sendAnEmail { @InvocableMethod(label='Test' description='sends an email') public static void sendEmailWithAttachment(List<id> listofQuoteHeader) { Map<Id, Application__c> quotesMap = new Map<Id, Application__c>([SELECT id,Contact__r.Email FROM Application__c WHERE Id IN :listofQuoteHeader]); 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; attachment.Name='Sign.png'; insert attachment; Messaging.SingleEmailMessage semail= new Messaging.SingleEmailMessage(); Messaging.EmailFileAttachment attach= new Messaging.EmailFileAttachment(); attach.setFileName('AttachmentEmailFile.pdf'); attach.setBody(b); semail.setSubject('Quote Issued'); // String[] emailIds= new String[]{'abc@gmail.com'}; String[] emailIds= new String[]{quotesMap.get(QuoteHeaderid)?.Contact__r.Email}; semail.setToAddresses(emailIds); semail.setPlainTextBody('Please find the attached quote details'); semail.setFileAttachments(new Messaging.EmailFileAttachment[]{attach}); Messaging.sendEmail(new Messaging.SingleEmailMessage[]{semail}); } } }
<apex:page renderAs="PDF" > <h1 >Congratulations </h1 > Name:Application__c.Contact__r.Name </apex:page>
Please check this thread with similar code example for better understanding:
https://salesforce.stackexchange.com/questions/44225/visualforce-page-on-custom-object-related-to-standard-object
Hope above information helps, Please mark as Best Answer so that it can help others in the future.
Thanks.