function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
AndreDBAndreDB 

Looking to create donation receipts

Hello,

 

I am looking to have a quick, efficient way to automatically (or very simply) create tax-deductible donation thank you/receipt letters immediately after I enter a donation into Salesforce. Ideally, these would be pdfs that could be instantly emailed to the respective contact via the click of a button (or even better, automatically). 

 

A Salesforce rep directed me to this forum as a way to do it. Can anyone help me get it set up? 

 

P.S. I have already looked into CongaComposer and unfortunately >500$ a month is simply too expensive for our NFP organization.

Thanks!

 

Best Answer chosen by Admin (Salesforce Developers) 
Neeraj_ChauriyaNeeraj_Chauriya

Hi,

One solution you could implement is as follows:

- Create a visualforce page which will be rendered in PDF(Using renderAs="PDF" attribute), design this page in the recipt format and include all the neccessary data you want to put in the receipt or document for a particular donation record.
- Write an after insert trigger on the object(which you are using to store donation).
- From the trigger create instance of the visualforce page (which will be rendered as PDF document) and send this document as an atachment to the appropriate email address:

Visualfoprce page:

<apex:page standardController="YourObject" extensions="YourController" renderAs="PDF">
    <!--  Put the data for the receipt or document in this page, the content rendered in this page will be sent as an attachment with the email -->
</apex:page>

 

Trigger

Trigger DonationTrigger(After insert){

//get the donation record
//call the method to send the document as an attachment

}

 

Method to send email:


public void sendEmail(){
    PageReference pdfDocPage = Page.YourPageName;
    // Add record id in parameters(to be used by standardController)
    pdfDocPage.getParameters().put('id',Your_Object_Id);
 
    // returns the output of the page as a PDF
    // Remember that getContent() method is not supported in test context
    Blob pdfDocPageBody = pdfDocPage.getContent();
    
    // Create attachment record    
    Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
    attach.setContentType('application/pdf');
    attach.setFileName('FileName.pdf');    
    attach.Body = body;
 
    Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
    mail.setToAddresses(new String[] { mailTo });
    mail.setSubject("Email Subject");
    mail.setPlainTextBody("Email body");
    mail.setFileAttachments(new Messaging.EmailFileAttachment[] { attach });
 
    // Send the email
    Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}

 


Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other's benefit.

All Answers

Neeraj_ChauriyaNeeraj_Chauriya

Hi,

One solution you could implement is as follows:

- Create a visualforce page which will be rendered in PDF(Using renderAs="PDF" attribute), design this page in the recipt format and include all the neccessary data you want to put in the receipt or document for a particular donation record.
- Write an after insert trigger on the object(which you are using to store donation).
- From the trigger create instance of the visualforce page (which will be rendered as PDF document) and send this document as an atachment to the appropriate email address:

Visualfoprce page:

<apex:page standardController="YourObject" extensions="YourController" renderAs="PDF">
    <!--  Put the data for the receipt or document in this page, the content rendered in this page will be sent as an attachment with the email -->
</apex:page>

 

Trigger

Trigger DonationTrigger(After insert){

//get the donation record
//call the method to send the document as an attachment

}

 

Method to send email:


public void sendEmail(){
    PageReference pdfDocPage = Page.YourPageName;
    // Add record id in parameters(to be used by standardController)
    pdfDocPage.getParameters().put('id',Your_Object_Id);
 
    // returns the output of the page as a PDF
    // Remember that getContent() method is not supported in test context
    Blob pdfDocPageBody = pdfDocPage.getContent();
    
    // Create attachment record    
    Messaging.EmailFileAttachment attach = new Messaging.EmailFileAttachment();
    attach.setContentType('application/pdf');
    attach.setFileName('FileName.pdf');    
    attach.Body = body;
 
    Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
    mail.setToAddresses(new String[] { mailTo });
    mail.setSubject("Email Subject");
    mail.setPlainTextBody("Email body");
    mail.setFileAttachments(new Messaging.EmailFileAttachment[] { attach });
 
    // Send the email
    Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}

 


Important :
Hit Kudos if this provides you with useful information and if this is what you where looking for then please mark it as a solution for other's benefit.

This was selected as the best answer
AndreDBAndreDB

That does look great as to what I am looking to do, although unfortuantly I do not have any experience with VisualForce. I have worked extensively with C, C++ and Python though, so when it comes to code I am not clueless.

 

Are you able to help me input that into the correct terminal? 

Neeraj_ChauriyaNeeraj_Chauriya

Hi,

 

Please proceed with the implementation and let me know if you face any issues.

 

 

AndreDBAndreDB

Ok, thanks.

 

I likely won't have time to look at this for a week or two, but when I do, I'll get back to you.

 

Thanks again!