This section walks through the configuration required to automate PDF process described in the the Manual section.
Save time for your sales rep and define “PDF Rules” to auto generate PDF and Email based on your business logic without clicking Create PDF button, then select a Template, and then Email. For example, if an opportunity is Close Won, generate and email the PDF to recipients using pre-defined templates. (Note: It’s highly recommended to test the automation with internal users before enabling it for customers).
Please configure these one time settings.
Go to PDF Settings tab >> PDF Rules >> Select “Auto Generate PDF” flag.
Select an object from the picklist to view all the rules for that object. Click “New” to configure a new rule or click the pencil icon to edit/view an existing one.
Sample PDF Rule
Object: Select the object the rule is applicable to
Field Name and Field Value: These fields define evaluation criteria for rule to fire. In above screenshot, the PDF will be generated when Opportunity StageName changes to “Closed Won”
Active: Select the checkbox to activate the rule
Name: Enter a name which is easy to recognize
PDF Template: The template that will be used to generate the PDF if the Field Name and Field Value match. List of available templates is filtered based on the Object selected
Email Template: The template that will be used to email the PDF to recipients. Note: Once an email template is provided, an email will be sent using this template. It is recommended to test the automation by providing an internal email id in the “Internal Email Id” field
Internal Email Id(s): Specify internal email IDs (separated by semi-colon) to test the the automation before enabling it for the end customers. If populated, emails will be sent to the email ids specified and not to the Recipients. Once you have tested the automation, make this field blank to start sending emails to recipients
CC me and BCC me: If checked, the user who modified the record will be added as CC or BCC to the email sent to the recipients
To evaluate a rule based on multiple fields, create a custom Formula field with the business rule and then specify the API Name of that formula field as the Field Name above. For example, if rule needs to be executed based Opportunity StageName and Payment Mode, following formula can be used in the formula field –
IF( ISPICKVAL(StageName, 'Proposal'), IF( ISPICKVAL(Payment_Mode__c, 'Bank Wire'), 'Bank Invoice', IF( ISPICKVAL(Payment_Mode__c, 'Paypal'), 'Paypal Invoice', '' ) ), '' )
Assuming the API name of the formula field is “Send_Invoice__c”, the rules will be configured as below
Notes:
You need to create following trigger in order to automate PDF generation for other objects than listed above.
Note :
trigger CreatePDF on My_Object__c (after insert, after update) { if(UserInfo.isCurrentUserLicensed('sfcloud2') && !sfcloud2.QuotePDF_Utility.isTriggerRunning) { //Copy default recipients sfcloud2.QuotePDF_Utility.copyRecipient('My_Object__c', trigger.new); //Create PDF and store as an attachment sfcloud2.QuotePDF_Utility.createPDFAndEmail('My_Object__c', trigger.new); } }
Salesforce requires a test class with minimum 75% code coverage to deploy any code to production org. Please see see sample test class below for the above trigger. You will have to modify below test class for it to work with the object you are configuring.
@isTest(SeeAllData=false) private class createObjectPDF_TEST { @testSetup static void createData(){ //Create default PDF setting sfcloud2__PDF__c pdfSettings = new sfcloud2__PDF__c( Name = 'Default Configuration', sfcloud2__Auto_Generate_PDF__c = true, sfcloud2__Filter_Templates__c = false, sfcloud2__Hide_Related_Objects__c = 'ProcessInstance,ProcessInstanceHistory,NetworkActivityAudit,ContentVersion' ); insert pdfSettings; //Create default Recipient setting sfcloud2__Default_Recipients__c recipientSetting = new sfcloud2__Default_Recipients__c( Name = 'My_Object_test', sfcloud2__Object__c = 'My_Object__c', sfcloud2__Receive_email_as__c = 'To', sfcloud2__Primary__c = true, sfcloud2__Recipient__c = 'Contact__c' //Replace this with the API name of the recipient field ); insert recipientSetting; //Depending on the object you will have to update below code to make sure all the required fields are accounted for My_Object__c myObj = new My_Object__c (Name='TestRecipients'); insert myObj; } @isTest static void validateData() { My_Object__c myObj = [SELECT Id FROM My_Object__c WHERE Name = 'TestRecipients' LIMIT 1]; //**Please make sure you have followed all the steps in the guide**// //Below code will not compile if you have not created the lookup field on Recipients object List<sfcloud2__Recipients__c> recipients = [SELECT Id FROM sfcloud2__Recipients__c WHERE My_Object__c =:myObj.Id]; //Below assertion will fail if you have not configured the Recipient custom settings for the object System.assertEquals(recipients.size()>0, true); } }