How to get congacomposer online pdf into mail attachment saleforce
To attach a Conga Composer-generated PDF to an email in Salesforce, you'll need to follow these steps:
Prerequisites:
- Conga Composer is installed and configured in your Salesforce org.
- You have a PDF template created in Conga Composer.
- You have a Salesforce email template or a custom email template that allows attachments.
Step 1: Generate the PDF using Conga Composer
- Go to the Conga Composer dashboard and select the PDF template you want to use.
- Configure the template with the necessary data, such as merge fields, using the Conga Composer interface.
- Click the "Generate PDF" button to create the PDF document.
Step 2: Save the PDF to a Salesforce attachment
- In Salesforce, go to the "Attachments" related list on the object where you want to attach the PDF (e.g., Account, Contact, Opportunity, etc.).
- Click the "New" button to create a new attachment.
- Select the PDF file generated in Step 1 and upload it to Salesforce.
Step 3: Create a Salesforce email template or use a custom email template
- Go to Setup > Email > Email Templates.
- Click "New" to create a new email template or edit an existing one.
- In the email template, add a placeholder for the attachment using the "Insert Field" button. For example, you can add a placeholder for the PDF attachment using the "Attachment" field.
Step 4: Use Apex code to attach the PDF to the email
- Create a new Apex class or edit an existing one.
- Use the
Messaging.SingleEmailMessage
class to create a new email message. - Set the
setBody
method to use the email template you created in Step 3. - Use the
addAttachment
method to attach the PDF file generated in Step 1 to the email message.
Here's an example Apex code snippet:
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setBody('Your Email Template Name');
mail.setSubject('Your Email Subject');
mail.addAttachment('Your_Attachment_Name', Blob.valueOf(attachment.getBlob()));
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
Step 5: Trigger the Apex code
- Create a new trigger or edit an existing one.
- Set the trigger to fire on the object where you want to attach the PDF (e.g., Account, Contact, Opportunity, etc.).
- Use the Apex code snippet from Step 4 as the trigger code.
By following these steps, you should be able to attach a Conga Composer-generated PDF to an email in Salesforce.