APEX based DDP generation using LOOPlus

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.

Posted

in

,

by


Related Posts

Comments

9 responses to “APEX based DDP generation using LOOPlus”

  1. Drawloop Technologies Avatar
    Drawloop Technologies

    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. LG Avatar
    LG

    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. JitendraZaa Avatar
      JitendraZaa

      In above example : Line number 24 says “opp.id”, so it will be visible in attachment section of this sopportunity

      1. LG Avatar
        LG

        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);
        }

        }
        }

        1. Vennila Avatar
          Vennila

          I am also facing this same issue now. do you have correct code for this now?

  3. becky012 Avatar
    becky012

    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. Abhimanyu Singh Tanwar Avatar
    Abhimanyu Singh Tanwar

    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. Vennila Avatar
      Vennila

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

  5. Rajat Maheshwari Avatar
    Rajat Maheshwari

    Hi Jitendra,
    Thanks for your post!
    In context of “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.”, I had tried using batch class with keeping batch size :- 100 and run the batch for more than 100 records, on which loop message webservice callout performed. It worked well for me.

    As per analysis, It seems – 100 callout using batch class will not create any issue . Determining factor to decide batch size :- 100/n where n is number of callout in execute method for 1 record.

    So, as per latest, Is it correct statement : 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 ?

    Please advise.

    Thanks

Leave a Reply to Abhimanyu Singh TanwarCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Jitendra Zaa

Subscribe now to keep reading and get access to the full archive.

Continue Reading