Topic
Instructions
** This Sample button will not be supported for any additional modification. This button falls under the realm of custom buttons.
- Navigate to Salesforce setup
- Search in Quick Find “Visualforce Pages”
- Click “New”
- Give the Page a ‘Label’ & ‘Name’
(Sample)- Label = ‘Drawloop - Order DocQ by Name’
- Name = ‘Drawloop_Order_DocQ_by_Name’
- Copy the below Visualforce page sample and paste it in the ‘Visualforce Markup’ Section.
- Click Save.
- Navigate to Salesforce Setup
- Search in Salesforce setup > Object Manager
- Select the “Document Request” object.
- Under ‘Buttons, Links, and Actions’ Select ‘New Button or Link’
- Give the Button a ‘Label’ & ‘Name’
(Sample)- Label = ‘Merge by Name’
- Name = ‘Merge_by_Name’
- Select Display type = ‘List Button’
- Select Behavior = ‘Display in existing window with sidebar’
- Select Content Type = ‘Visualforce Page’
- Select Content = ‘Drawloop - Order DocQ by Name’
- Click ‘Save’
- Navigate back to the ‘Document Request object’ to add your button to the page layout.
- Now, Navigate to ‘Search Layout’ on the ‘Document Request object’
- Select ‘List View Button Layout'
- Select Edit from the dropdown on the 'List View Layout’
- Move the newly created button from ‘Available Buttons’ to ‘Selected Buttons’
- Click ‘Save’
Now Navigate to the Document Queue and merge the selected files. They will merge in alphabetical order.
Additional Information
<apex:page standardController="Loop__Document_Request__c" recordSetVar="units">
<apex:includeScript value="/soap/ajax/26.0/connection.js"/>
<apex:includeScript value="/support/console/26.0/integration.js"/>
<apex:dataTable value="{!selected}" var="un">
<apex:column >
<apex:outputLabel styleClass="ids">{!un.Id}</apex:outputLabel>
</apex:column>
</apex:dataTable>
<style>
.ids{visibility : hidden}
</style>
<script type="text/javascript">
document.addEventListener("DOMContentLoaded", function(event) {
debugger;
sforce.connection.sessionId = '{!$Api.Session_ID}';
var elems = document.body.getElementsByClassName("ids");
var ids = new Array();
for (var i = elems.length - 1; i >= 0; i--) {
//the \n is regex for line break
ids[i] = elems[i].innerHTML.replace(/\n/, '');
}
if (ids.length < 1) {
alert("No items are currently selected.");
} else {
var docIds = new Array();
var updatedIds = new Array();
try {
var qr = sforce.connection.query("SELECT Loop__Document_Id__c FROM Loop__Document_Request__cWHERE Id IN ('"+ ids.join("','") +"') ORDER by Loop__Document_Name__c");
} catch(e) { console.log(e); alert('An error has occurred. Please try again.'); return; }
if (qr.size > 0)
{
for (var i=0; i < qr.size; i++)
{
q = (qr.records[i] ? qr.records[i] : qr.records);
if(q && q.Loop__Document_Id__c && q.Loop__Document_Id__c.substring(0,3) == '015')
{
docIds.push(q.Loop__Document_Id__c);
var request = new sforce.SObject("Loop__Document_Request__c");
request.Id = ids[i];
request.Loop__Status__c = "Merged";
updatedIds.push(request);
}
}
}
try { sforce.connection.update(updatedIds);
} catch(e) { alert("Unable to update all requests' statuses."); }
{
var redirectUrl = "/apex/loop__loopit?eid=" + ids[0] + "&docIds=" + docIds.join('-') + "&type=merge" + "&mergetype=bytype";
if (sforce && sforce.one && sforce.one.navigateToURL) {
sforce.one.navigateToURL(redirectUrl);
} else {
window.location.href = redirectUrl;
}
}
}
});
</script>
</apex:page>