To automate the document generation in salesforce, we have two well known AppEchange products named “Conga Composer” and “LOOPlus from DrawLoop“. Both products are well used in industry and both have advantages and disadvantages over the need and situation.
This article depicts automating the document generation using Apex in LOOPlus. As i have been through this situation and didn’t find any resource on web to automate the document generation using Apex, so i thought to put this article.
Advantage of LOOPlus over Conga Composer:
- The one advantage which i know is that using LOOPlus you can combine all the attachments into single one which is not possible in Conga Composer.
Navigate to this URL to install the trial version of Drawloop (LOOPlus) from AppExchange.
To use the Drawloop API we need to use the “Business” version of LOOPlus. To activate this, navigate to “LOOP” app and then “DDP Admin”. Click on button “Modify Subscription services“. New Page will open, select “Business” in LOOPlus level as shown in below image.
After this step, email “loopsupport@drawloop.com” to enable Outbound Messaging for your organization, only after that you can use the Apex for LOOPlus.
For this article, i hope that you already know how to generate the DDP using DDP wizard.
Consider below DDP is generated for this article:
We need below two ID for using Apex:
- ID of the DDP as shown in above image
- ID of the Delivery Option (We can have more than one ID but we need only one ID of Attachment type of delivery option)
I am going to add one button in List View of “Opportunity” and when i will select the opportunities, and click on that button Visualforce Page will invoke resulting in execution of DDP from Apex.
Visualforce code:
<apex:page standardController="Opportunity" recordSetVar="opportunities" extensions="MassLoop" action="{!massMerge}" ></apex:page>
Apex code (Extension class):
public class MassLoop{ private final List<Opportunity> opps; public MassLoop(ApexPages.StandardSetController controller) { this.opps = (List<Opportunity>) controller.getSelected(); } public PageReference massMerge(){ try{ for(Opportunity opp : opps){ List<Attachment> nas= [select id,name from Attachment where parentid=:opp.id]; String attachIds=''; for(Attachment na :nas){ attachIds = attachIds+na.id+'|'; } Map<string, string> variables; if(attachIds.length()>1){ attachIds = attachIds.substring(0,attachIds.length()-1); //Below ID is of the "Delivery Option" of DDP variables = new Map<string, string> { 'deploy' => 'a059000000169y6','attachIds'=>attachIds }; } else{ variables = new Map<string, string> { 'deploy' => 'a059000000169y6' }; } //Below ID is of main "DDP" Loop.loopMessage.send(opp.id,'a069000000EQduC',variables, 'ap1'); } } catch(Exception e){ system.debug('--------e-----:'+e); } PageReference page = new PageReference('/006/o'); page.setRedirect(true); return page; } }
Note : Only 10 records can be selected at a time because it calls the webservice of loop to generate the document and as per Salesforce limit we can have only 10 callout per transaction.
Leave a Reply