APEX based DDP generation using LOOPlus

Author posted by Jitendra on Posted on under category Categories Apex, Salesforce and tagged as Tags , , with 8 Comments on APEX based DDP generation using LOOPlus

Example of generating dynamic document packages (DDP) using Apex and LOOPlus in Salesforce

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.

Enabling Business Version of DrawLoop
Enabling Business Version of DrawLoop

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:

DDP Using LOOPlus of Drawloop
DDP Using LOOPlus of Drawloop

We need below two ID for using Apex:

  1. ID of the DDP as shown in above image
  2. 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.

Related posts

8 thoughts on “APEX based DDP generation using LOOPlus”

  1. Great post! We do have new methods for calling DDPs within Apex. Please contact us to learn more or check our support site for documentation when it becomes available.

  2. Hi Jitendra,

    Nice post! I am new to salesforce apex and I tried this solution but I am executing this class from developer console anonymously. My question is where do I see the converted file?

    Thanks

      1. Thanks Jitendra. Do I need to do anything else besides you have mentioned in article? I mean is there any other steps needed?

        I have choose delivery options as attachment but I don’t see any attachment in opportunity object. I am just doing it for one opportunity and triggering this piece of code from developer console. Please help me with this.

        Thanks in advance.

        public class TesClass{

        public static void massMerge(){
        system.debug(‘Entering to generate document.’);
        try{

        Map variables;

        variables = new Map { ‘deploy’ => ‘a0BP0000005Tj8O’ };

        system.debug(‘Sending as attachment’ );
        //Below ID is of main “DDP”
        Loop.loopMessage.send(‘006P0000004tsIc’,’a0CP00000045U47′,variables, ‘ap1’);
        system.debug(‘Done!’ );
        }

        catch(Exception e){
        system.debug(‘——–e—–:’+e);
        }

        }
        }

  3. Hi,
    I am trying to send an email via apex using Drawloop. In my scenario checking a checkbox on an opportunity would trigger the generation of a certain ddp and an email to the primary contact of this opportunity. For the moment I am unable to do none of the two. And the Drawloop documentation offers nothing on this … Would you have a starting idea about how I should do this? Thanks

  4. I am trying to use in future method to avoid limit, but it is asking for session ID. The error I am getting is “Loop.loopMessage.MissingValueException: A Session Id is required.”

    1. I have tried this logic in trigger and getting this same error. Have you resolved this issue? can you please share solution for this?

Leave a Reply

Your email address will not be published. Required fields are marked *