Document Generation in Salesforce with Nintex DocGen via Apex Code

Document Generation in Salesforce with Nintex DocGen via Apex Code

Hello All,

Welcome to another part of Nintex Document Generation in salesforce and this gonna be code-based. Before going to dive into it, I request you all to please look into the previous blog for the basic understanding of  Nintex Docgen.

Now let's start using it in an advanced way with Apex Code.

Before writing apex code ensure that you have a document package with the template and delivery options, if not let's create it.

  • First, make a document package
  • Second, attach a template to it
  • Third, create a delivery option for that package

Now for apex code, as Nintex is a managed package so we can’t use modify the code but we can use the method of their class.

For finding which method is to use you can find it from here,

We have created an apex class and used their methods such as,

public class DrawloopDocumentGeneration {
    public static void drawloopDocumentGeneration() {
        try {
            Loop.loopMessage lm = new Loop.loopMessage();
            for(Opportunity bps : [Select Id from Opportunity Limit 120]) {
                Map<string, string> variables; // MAIN RECORD ID - SAME OBJECT AS THE DDP RECORD TYPE SPECIFIES' // DDP ID
                lm.requests.add(new Loop.loopMessage.loopMessageRequest( bps.Id, 'a5q0U0000000Wgr', new Map<string, string> { 'deploy' => 'a5o0U00000002hI' } //DELIVERY ID ));
            }
            // SEND ALL DDP RUN REQUESTS IN A SINGLE CALL OUT
            lm.sendAllRequests();
        }
        catch(Exception e){
            system.debug('--------e-----:'+e); 
        }
    }
}

After creating Apex class, now it's time to invoke class and check our document is generating or not.

For this open your Execute Anonymous Window in your developer console,  and write

DrawloopDocumentGeneration.drawloopDocumentGeneration();

And execute this. That creates a document, you can check the attachment of that record.

Happy Salesforce 🙂

Thanks

Related Articles

Responses

  1. Hi,

    What is this 2nd Id here in the below line. 'a5q0U0000000Wgr'

    lm.requests.add(new Loop.loopMessage.loopMessageRequest( bps.Id, ‘a5q0U0000000Wgr’, new Map<string, string> { ‘deploy’ => ‘a5o0U00000002hI’ } //DELIVERY ID ));

    Thanks