SmallBuilder Help
AppExchangeContact Us
πŸ‡ΊπŸ‡Έ English
πŸ‡ΊπŸ‡Έ English
  • SmallBuilder Help
  • Getting started with SmallBuilder
    • License and Permission Set Assignment
    • Organization Currency Setup
    • Connected App Configuration
  • πŸ“¦SmallBuilder Line Items
    • Release Notes
      • '25 Update
        • v 1.38
        • v 1.37
    • SmallBuilder Line Items Overview
    • Getting Started
      • Assigning Licenses and Permissions
      • Organization Currency Setup
      • Connected App Setup
    • Builder
      • Getting Stared with the Builder
      • Default Setting
        • Responsive Screen Configuration for Devices
        • Adjusting Editor Screen Ratio
        • Modifying Editor Labels
        • Lookup Selector Settings
          • Search All on Load
          • Expand Filters by Default
          • Allow Select Duplicate Item
          • Caching to Improve Performance
          • Records Per Page
        • Line Item Editor Settings
          • Show Summary
          • Freeze First Column
      • Builder Setup Steps
        • Relate Objects
          • Parent Object
          • Line Item Object
            • Set Object and Parent Reference Field
            • Set Filters and Sorting for Saved Line Items
            • Control Line Item Deletion
            • Set Auto-Numbering
          • Lookup Object
            • Select Lookup Reference Field
            • Set Keyword Search
            • Block Lookup Selector
            • Set Filters and Sorting for Lookup Records
        • Setup Lookup Selector
          • Add Columns
          • Reorder Columns
          • Change Column Labels
          • Set Column Width
          • Change Text Alignment
          • Add Virtual Columns for DataSource
        • Setup Line Item Editor
          • Add Columns
          • Reorder Columns
          • Change Column Labels
          • Set Default Value
          • Source Field: Assigning Default Values from Parent or Lookup Fields
          • Set Column Width
          • Change Text Alignment
          • Set Field Input to Read-Only
          • Set Field Input as Required
          • Display Totals
          • Hidden Setting for Line Item Editor Columns
          • Exclude Certain Fields from Saving
        • Preview
        • Activate
        • Create Button and Add to Page Layout
      • DataSource
        • Basic DataSource: Retrieve Related Object Data
        • Advanced: Retrieve Data Using Apex Classes
      • Cloning the Builder
      • Resetting a Builder
      • Insert Filters Using the Query Wizard
      • Inserting Custom Labels into Editor Labels
    • Product Option
      • Product Option Setup Steps
        • Activate Product Options
        • Configure Product Options
          • Default Setting
          • Line Item Setting
        • Configure Product Option Data
      • Display and Storage of Line Item Option Values
    • Use Cases
      • Utilizing the Editor’s Aura Component
    • FAQ
  • πŸ“¦SmallBuilder Lists
    • SmallBuilder Lists Introduction
    • Getting Started with SmallBuilder Lists
      • Assigning Licenses and Permissions
      • Organization Currency Setup
      • Connected App Setup
    • Getting Started with Builder
    • Builder Setup Steps
      • Default Setup
        • Title
        • Legend
        • Allow Export
        • Allow Import
        • Show Icon
      • Datatable Setup
        • QUERY
        • Multi Selectable
        • Show Summary
        • Add and Edit Columns
          • Column Editing by Type
        • Add Virtual Column
        • Add Row Action
      • Data Import Setup
      • Action Setup
        • Add Action
      • Filter Setup
        • Add and Configure Filters
          • Filter Editing by Type
      • Compact Configurator Setup
        • Add and Configure Columns
          • Editing by Column Type
      • Mobile Setup
      • DataSource Setup
        • Basic DataSource
          • Add and Configure Actions
        • Advanced DataSource
          • Writing an Apex Class
      • List Deployment and Management
        • Creating a List Configurator Manually
  • πŸ“¦SmallBuilder Documents
    • SmallBuilder Documents Introduction
    • Quick start
    • Components
    • Data Merge
      • Data Merge - Text
      • Data Merge - Related List
    • Document Job
    • Basic usage examples
      • How to pin a logo image to the top of the page
      • How to leave a gap between the components
      • How to add separators between the components
    • Advanced usage examples
      • Creating an invoice template
      • Automatically email invoices with a trigger
    • FAQ
    • 🌟Release Note
      • '24 Update
        • v. 1.50 ~
  • πŸ“¦SmallBuilder Schedules
    • SmallBuilder Schedules Introduction
    • Quick start: creating a new Schedule configurator
    • Detailed setup guide
      • Basic settings (Side Panel)
      • Linked objects setup
      • Control Field setup
      • Schedule Object setup
      • Saving and activating
    • FAQ
  • ❓SmallBuilder Troubleshooting
    • SmallBuilder Troubleshooting Help
      • Add Button Warning (If the button is not added to the page)
      • Add Tab Warning (Tabs are created and added to the app, but not visible)
Powered by GitBook
On this page

Was this helpful?

Export as PDF
  1. SmallBuilder Documents
  2. Advanced usage examples

Automatically email invoices with a trigger

Automatically send an email when a Quote is Accepted

Example of calling a function when the Status value of the Quote object becomes Accepted:

trigger Quote on Quote (after update) {
    
    public List<Quote>      newObjList  {get; set;}
    public Map<Id, Quote>   oldObj      {get; set;}

    newObjList = (List<Quote>)Trigger.new;
    oldObj = (Map<Id, Quote>)Trigger.oldMap;
    if (trigger.isAfter && trigger.isUpdate){   
        for(Quote qu : trigger.new){   
            if (qu.Status == 'Accepted' && qu.Status != oldObj.get(qu.id).Status){
                // Pass the template Id and recordId as parameters
                String templateId = DocumentCustomController.getTemplateId();
                DocumentCustomController.triggeredSavePdf(qu.Id, templateId);
            }
        }        
    }
    
}

Example function to get a template ID from the template name:

public static String getTemplateId() {
    String templateId = [SELECT Id 
                            FROM SBLD__DocumentBuilder__c
                            WHERE name = 'BillingStatement' 
                            WITH SECURITY_ENFORCED
                            ORDER BY CreatedDate DESC
                            LIMIT 1][0].Id;
    return templateId;
}

Example function to send an email to the user:

public static void sendEmailToUser( List<String> listAttachement) {
    // Add basic details to the email:
    Messaging.SingleEmailMessage clsSingleEmailMessage = new Messaging.SingleEmailMessage();
    clsSingleEmailMessage.setToAddresses(new List<String>{'abc@example.com'});
    clsSingleEmailMessage.setSubject('Email Subject');
    clsSingleEmailMessage.setPlainTextBody('Email Body');
    
    // Add attachment
    ContentVersion clsContentVersion = [SELECT VersionData, PathOnClient FROM ContentVersion WHERE ContentDocumentId = :listAttachement.get(0) WITH SECURITY_ENFORCED][0];
    Messaging.EmailFileAttachment clsEmailFileAttachment = new Messaging.EmailFileAttachment();
    clsEmailFileAttachment.setFileName(clsContentVersion.pathOnClient); 
    clsEmailFileAttachment.setBody(clsContentVersion.versionData);
    clsSingleEmailMessage.setFileAttachments(new Messaging.EmailFileAttachment[] {clsEmailFileAttachment});
    
    // Send the prepared email
    Messaging.sendEmail(new Messaging.SingleEmailMessage[]{clsSingleEmailMessage});     
        
}

Example of saving a Document Template as a PDF

// Saving Document Template to PDF
@future(callout = true)
public static void triggeredSavePdf(String recordId, String templateId) {

    // Create PDF
    PageReference pdfPage = new PageReference('/apex/SBLD__DocumentBuilderTemplate?recordId=' + templateId + '&targetId=' + recordId);
    Blob pdfContent;

    if(Test.isRunningTest()) { 
        pdfContent = blob.valueOf('Unit.Test'); 
    }else {
        pdfContent = pdfPage.getContentAsPDF();
    }
        
    String title = 'BillingStatement.pdf';

    // Add ContentVersion   
    ContentVersion cv           = new ContentVersion();
    cv.VersionData              = pdfContent;
    cv.Title                    = title;
    cv.PathOnClient             = title;
    cv.OwnerId                  = UserInfo.getUserId();
    cv.ContentLocation          = 'S';

    insert cv;
    
    // Add ContentDocumentLink
    Id conDocId = [SELECT ContentDocumentId FROM ContentVersion WHERE Id =:cv.Id WITH SECURITY_ENFORCED ].ContentDocumentId;
    ContentDocumentLink cdl = new ContentDocumentLink();
    cdl.ContentDocumentId = conDocId;
    cdl.LinkedEntityId = recordId;
    cdl.ShareType = 'V';
    cdl.Visibility = 'AllUsers';
		
    if (Schema.sObjectType.ContentDocumentLink.fields.ContentDocumentId.isCreateable()) {
            Database.insert(cdl);
    }
    
    // Call the email send method with the attachment added
    listAttachement = new List<String>{conDocId};
    sendEmailToUser(listAttachement);
}
PreviousCreating an invoice templateNextFAQ

Last updated 1 year ago

Was this helpful?

πŸ“¦