Mass DDPs in Lightning

Woohoo! We can FINALLY do Mass Drawloop DDPs in Lightning. 

Here's the docco https://community.nintex.com/t5/How-To-s/Creating-Mass-Button-in-Lightning/ta-p/92630

But it's not very helpful. 

Here's the steps

  1. Create the VF Page as shown for the Object you want to use the button on. I will come back to customising the VF page a bit later. Name it something useful like DDPObjectDocumentName
  2. Ensure you assign permissions to the VF page for all users that need to use the button. I would suggest creating a Permission Set for this. 
  3. Go to the Object and create your Button that uses the VF page - remember to choose List Button and Display Checkboxes, and display the button on the list view by going to Search Layouts. I do think this step is way easier than stuffing around with the Drawloop button wizard thingo. 
  4. Test it out. 

Yeah it sort of works... And it's ugly... 

But it doesn't work the way your magic Classic buttons do, does it? My Classic buttons have the DDPId and the DeploymentId already defined, and the Mass DDP runs automatically. 

This is where we get to play with the VF page a bit more, and customise it. 

Grab the Javascript code from your classic button

{!REQUIRESCRIPT("/soap/ajax/26.0/connection.js")} 
{!REQUIRESCRIPT("/support/console/26.0/integration.js")} 

var ids = {!GETRECORDIDS($ObjectType.TopUpPay__c)}; 
if (!ids || ids.length < 1) 
alert("Please select at least one record."); 
else 
{ 
var redirectUrl = "/apex/loop__masslooplus?&retURL=" + encodeURI(window.location.pathname+window.location.search); 
redirectUrl += "&recordIds="+ids.join(","); 
redirectUrl += "&sessionId={!$Api.Session_ID}"; 
redirectUrl += "&contactField=StatementToID__c&hidecontact=true&hideddp=true&autorun=true&ddpIds=a0t6F00000RN3hFQAT&deploy=a0r6F00000DKZIcQAP"; 
window.location.href = redirectUrl; 
}  


Grab the three lines before the window.location.href and copy those. 

Now modify the bottom of your VF page to look like this

            var instanceName = window.location.hostname;
            var newLocation = '/apex/loop__jobqueuestatus';
            console.log(instanceName+newLocation);
            var redirectUrl = '/apex/loop__masslooplus?';
            redirectUrl += '&recordIds='+ids.join(','); 
            redirectUrl += '&sessionId={!$Api.Session_ID}'; 
            redirectUrl += '&contactField=StatementToID__c&hidecontact=true&hideddp=true&autorun=true&ddpIds=a0t6F00000RN3hFQAT&deploy=a0r6F00000DKZIcQAP'; 
            redirectUrl += '&retURL='+newLocation;
            if (sforce && sforce.one && sforce.one.navigateToURL) {
    		sforce.one.navigateToURL(redirectUrl);

I've just replaced the " with ' to make sure it looked like the example. 

Test again, and voila! Mass DDPs in Lightning! And it redirects to the Job Queue Status at the end, which is handy. 

Oh, and when you test and you get a big ugly error... just make sure your deploys are not limited to Non-Mass only. 

And remember, your button is NOT available on the Recently Viewed list view. 


Now, some issues.... 

I don't want to create, and maintain and deploy VF pages for every single button. And I definitely don't want to hard code IDs into VF pages. eg I have a different Email Template for Australia and Singapore with different From Addresses so I need a different Deployment ID for different records. As the deployment ID is hard coded here, I don't want that. 

I tried creating the ID of the Deploy into a custom field, and referencing that into the VF page, but it doesn't work. As the VF page is basically still Javascript, it is only referencing the Id of each record you selected, it can't seem to reference any other fields. (My VF and JS skills are not enough to know how to tweak this). 

I would like to include the DDPId in a Custom Metadata Type field, but again, I could not quite work that out. 

So I relented and created two VF pages for now. But it's not right, and there must be a way to fix this.