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 to you all to please look into the previous blog for the basic understanding of  Nintex Docgen.

Now let’s start using it in advance way with apex code.

Before writing apex code ensure that you have 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 documents 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

2 Comments
  1. Salesforce | Mohammad
    Mohammad 1 year ago

    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

  2. Salesforce | Sneha Kathavate
    Sneha Kathavate 2 months ago

    I am getting [External] DocGen Package Outbound Message Error while I execute this

Leave a Reply

CONTACT US

We're not around right now. But you can send us an email and we'll get back to you, asap.

Sending

About Us

Forcetalks is a Salesforce collaboration platform for coders & developers, geeks & nerds, consultants & business heads, admins & architects, managers & marketers and of course the business owners. A community where you can learn from, where you can contribute to. For you. For Salesforce. Read More...

Copyright 2020 Forcetalks. All Right Reserved.

Log in with your credentials

or    

Forgot your details?