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
https://help.nintex.com/en-US/docgen/docservices/#docgen-sfdc/Services/apex/samples/ApexSamples.htm%3FTocPath%3DExtend%2520the%2520platform%7CApex%2520for%2520Nintex%2520DocGen%2520for%2520Salesforce%2520%7C_____1

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

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

Comments are closed.

Popular Salesforce Blogs