Streamlining Accounts Receivable Chaser Emails with Salesforce Automation
The current manual workflow for Accounts Receivable (AR) follow-ups—involving external data checks, manual lookups, template copying, data pasting, and file attachment hunting—is highly inefficient. The objective is to achieve a 'One-Click' action on a relevant record (likely an Invoice or Account) that generates a dynamically tailored chaser email, auto-populates data, and correctly attaches the corresponding Invoice PDF.
Given the constraints (standard Salesforce functionality only), Salesforce Flow (specifically a Screen Flow or Quick Action Flow) is the most appropriate tool for handling this orchestrated logic.
Architectural Considerations for the One-Click Solution
The solution requires coordinating data retrieval, conditional logic for template selection, dynamic content generation, and file management.
1. Trigger Mechanism (Quick Action)
To facilitate the 'one-click' requirement, the Flow should be initiated via a Quick Action placed on the relevant object (e.g., Invoice__c or Account). This action should launch a Screen Flow or a Record-Triggered Flow (if subsequent actions can be handled asynchronously, though a Screen Flow offers better user control for template selection).
2. Data Orchestration and Retrieval
The Flow must accurately identify which Contact to email and which Invoice PDF to attach.
Prerequisites & Assumptions:
- You have a custom object representing Invoices (e.g.,
Invoice__c). - The Invoice object is related to the Account and the primary Contact.
- The Invoice PDF documents are stored as Files specifically related to the
Invoice__crecord.
Flow Steps (Screen Flow Recommended):
- Get Record (Invoice/Account Data): Retrieve all necessary fields (Billing Address, Due Date, Amount, Contact Email, etc.) based on the record triggering the Flow.
- Decision Element (Days Past Due Logic): Use a Decision element to calculate the aging bucket (e.g., 15 days late, 30 days late, 60 days late). This dictates the email template and potential subject line.
- Screen Element (Optional Template Selection): Present a screen component allowing the user to manually select the determined template type or confirm the default selection. This fulfills the requirement: "Perhaps we could pick the template type manually."
- Get Records (File Retrieval): This is the critical step for attachments. Query the
ContentDocumentLinkrelated to the trigger record ID. You must filter this query to find the primary invoice attachment.
-- Pseudo-SOQL within the 'Get Records' element configuration for Files
SELECT ContentDocumentId FROM ContentDocumentLink
WHERE LinkedEntityId = :TriggerRecordId
AND ContentDocument.FileExtension = 'pdf'
AND IsDeleted = FALSE
ORDER BY CreatedDate DESC
LIMIT 1
Store the resulting ContentDocumentId of the latest (or relevant) PDF.
3. Dynamic Email Generation
Since standard Flow Email Alerts do not support complex dynamic content merging beyond simple fields, using the Action element SendEmail or composing the email content within the Flow is necessary to leverage the logic determined in Step 2.
- If using Email Templates (Classic/Lightning): Use the standard
EmailTemplatefields when calling theSendEmailaction. You must ensure the email template used supports the necessary merge fields (this is often simpler for basic AR notices). - If dynamic content is complex (based on aging bucket): Construct the Email Body and Subject using
Assignmentelements populated from the logic determined by the Decision elements. You can then use theSendEmailaction, specifying the plain text or HTML body constructed within the Flow.
4. Attaching the PDF
Attaching files dynamically in Flow requires working with the ContentDocumentLink object.
- Create ContentDocumentLink Records: If the Flow successfully retrieved the
ContentDocumentIdin Step 2, create a newContentDocumentLinkrecord to link this document to the newly created or targeted Email Message record (if you are drafting an activity) or directly to the Invoice record if that is the desired linkage.
Note on Attachments: If the goal is truly to send an email with the attachment, the standard Flow SendEmail action is limited in its native ability to attach arbitrary Salesforce Files directly based on IDs obtained mid-flow. The most robust approach often involves leveraging Apex or using an intermediary step to generate an EmailMessage record manually that includes the necessary ContentDocumentId references, or ensuring the File is linked correctly to an Activity created by the Flow.
Alternative (Simpler) Approach for Attachments: If the invoice is a standard attachment associated with an Email Message created by the Flow, link the ContentDocumentId to the related ContentDocumentLink on that EmailMessage record. If you are simply generating a Draft Email (Activity), you may need Apex assistance for complex file merging, although basic attachment linking is becoming more accessible in recent Flow updates.
Apex Integration for Complex File Handling (If Flow Fails)
If the precise attachment mechanism for dynamic Files proves too cumbersome or restrictive within declarative Flow limits, an Invocable Apex Method called from the Flow is the recommended fallback. Apex provides direct access to the Messaging.MassEmailMessage or ContentDocumentLink APIs, ensuring the correct PDF is attached regardless of how complex the criteria are.
Apex can receive the InvoiceId and TemplateType from the Flow, query the relevant file ID, construct the email (using rich template data if necessary), and send it, all while maintaining the single-click initiation point.
Key Takeaways
- Screen Flow is ideal for providing user interaction necessary for template selection and immediate execution.
- The primary technical hurdle is reliably querying for and attaching the correct PDF File (
ContentDocumentLink) referenced by the Invoice record. - Use Decision elements to drive dynamic email generation based on aging buckets.
- If native Flow attachment methods prove insufficient for dynamic files, transition the final email construction and sending logic to a robust Invocable Apex class called from the Flow.
Leave a Comment