You need to sign in to do that
Don't have an account?
Nishant Shrivastava 30
I want to update the field in database on the bases of checkboxes. i have a field Downloaded__c datatype checkbox, i need to make it true if the checkboxes are processed. it to be done through javascript in appended code. I shall be grateful to you
<apex:page sidebar="false" Controller="Invoice_details" showHeader="False" docType="html-5.0" readOnly="true">
<apex:includeScript value="/soap/ajax/47.0/connection.js"/>
<apex:includeScript value="/soap/ajax/47.0/apex.js"/>
<apex:includeScript value="{!$Resource.jszip}"/>
<apex:includeScript value="{!$Resource.FileSaver2}"/>
<html xmlns="https://www.w3.org/2000/svg" xmlns:xlink="https://www.w3.org/1999/xlink">
<head>
<apex:slds />
<style>
.displayBlock {
display: block;
}
.placeHolder {
margin-left: 50px;
margin-top: 50px;
Width: 50rem;
}
.Showall {
font-style: bold;
margin-top: 120px;
width: 100%;
}
.space {
font-style: italic;
font-size: 25px;
margin-left: 50px;
margin-top: 20px;
}
.slds-form-element__label slds-m-bottom_none {
font-size: 2rem;
}
.nishant {
font .
size: 1rem;
}
input.date {
cursor: pointer;
font-size: 18px;
margin: 12px;
padding: 4px;
width: auto;
text-align: center;
}
</style>
</head>
<body>
<apex:form title="form" styleClass="Showall" forceSSL="true" id="A">
<div class="slds-form-element">
<div class="slds-p-left_xx-large">
<label class="slds-checkbox_toggle slds-grid">
<span class="slds-form-element__label slds-m-bottom_none" style="font-size:.90rem"> Show All </span>
<input type="checkbox" name="checkbox-toggle-15" value="checkbox-toggle-15" aria-describedby="checkbox-toggle-15" onclick="getdata()" checked=""/>
<span id="checkbox-toggle-15" class="slds-checkbox_faux_container" aria-live="assertive" style="margin-left:15px">
<span class="slds-checkbox_faux"></span>
<span class="slds-checkbox_on">Enabled</span>
<span class="slds-checkbox_off">Disabled</span>
</span>
</label>
</div>
</div>
<div class="slds-grid slds-grid_align-space">
<div class="slds-p-top_xx-large">
<span>Date From
<apex:inputfield value="{!InvoiceInfo.kognoz1__Invoice_Date__c}" label="Start Date" id="datefrom"/>
</span>
</div>
<div class="slds-p-top_xx-large">
<span>Date To
<apex:inputfield value="{!InvoiceInfo.kognoz1__Invoice_Due_Date__c}" label="End Date"/>
</span>
</div>
<div class="slds-p-top_xx-large">
<apex:commandButton value="Search" action="{!display}" reRender="B"/>
</div>
</div>
<div class="slds-p-top_xx-large">
<apex:pageBlock >
<apex:pageBlockSection showHeader="false" id="B" columns="1" >
<apex:pageblocktable value="{!InvoiceList}" var="rs" id="A">
<apex:column >
<apex:facet name="header">
<input type="checkbox" id="selectAllCheckbox" onclick="selectAllCheckboxes(this)" />
<!--
<apex:inputcheckbox>
<apex:actionSupport event="onclick" onSubmit="return selectAllCheckboxes(this)" />
</apex:inputcheckbox>
-->
</apex:facet>
<apex:repeat value="{!rs.KI.attachments}" var="C">
<input type="checkbox" value="{!C.Id}" data-date="{!rs.KI.kognoz1__Invoice_Date__c}" data-account="{!rs.KI.kognoz1__Account__c}" data-opportunity="{!rs.KI.kognoz1__Opportunity__c}" data-Status="{!rs.KI.Downloaded__c}" Id="inputId" class="invoiceCheckBox" onClick="unselectSelectAllCheckboxes(this)" />
</apex:repeat>
</apex:column>
<apex:column value="{!rs.KI.kognoz1__Invoice_Date__c}" headerValue="DATE"/>
<apex:column value="{!rs.KI.kognoz1__Account__c}" headerValue="Account"/>
<apex:column value="{!rs.KI.kognoz1__Opportunity__c}" headerValue="Opportunity"/>
<apex:column headerValue="Files">
<apex:repeat value="{!rs.KI.attachments}" var="C">
<apex:outputLink value="https://c.cs101.content.force.com/servlet/servlet.FileDownload?file={!C.Id}&operationContext=S1" target="_blank" rel="nofollow">
{!C.name}
</apex:outputLink>
</apex:repeat>
</apex:column>
<apex:column value="{!rs.KI.Downloaded__c}" headerValue="Status"/>
</apex:pageblocktable>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:panelGrid columns="5" cellspacing="1" cellpadding="1">
<div class="slds-p-left_xx-large">
<apex:commandbutton value="Download" onclick="return downloadZip(this)" />
<apex:commandbutton value="Previous" action="{!previous}" disabled="{!DisablePrevious}" reRender="A,B"/>
<apex:commandbutton value="Next" action="{!next}" reRender="A,B"/>
</div>
<apex:actionStatus id="status" startText="Loading"/>
</apex:panelGrid>
</div>
</apex:form>
<script>
// select / unselect All
function selectAllCheckboxes(checkbox) {
var invoiceCheckBoxes = document.getElementsByClassName('invoiceCheckBox');
for(var i=0; i<invoiceCheckBoxes.length; i++){
invoiceCheckBoxes[i].checked = checkbox.checked;
}
}
// unselect selectAll-checkbox
function unselectSelectAllCheckboxes(checkbox) {
if(!checkbox.checked) {
var selectAllCheckBox = document.getElementById('selectAllCheckbox');
selectAllCheckBox.checked = false;
}
}
//Get the attachment ids of all selected checkboxes/records
function getCheckedRecordsData() {
const checkboxes = document.querySelectorAll('input[type=checkbox].invoiceCheckBox:checked');
let recordsData = [];
for (let i = 0, l = checkboxes.length; i < l; i++) {
recordsData.push({date: checkboxes[i].dataset.date, account: checkboxes[i].dataset.account, opportunity: checkboxes[i].dataset.opportunity, attachmentId: checkboxes[i].value, Status : checkboxes[i].Downloaded__c,});
}
return recordsData;
}
//Generating and download the zip files with all attachments
function downloadZip(btnElement) {
//Make btn disabled while generating zip with all attachments
btnElement.disabled = true;
const zip = new JSZip();
let promises = [];
let checkedRecordsData = this.getCheckedRecordsData();
if(!checkedRecordsData.length) {
btnElement.disabled = false;
return;
};
console.log('CHECK DATA', checkedRecordsData);
for (let i = 0, l = checkedRecordsData.length; i < l; i++) {
promises.push(new Promise((resolve, reject) => {
try {
//Get attachment id and set salesforce sessionId
const recordData = checkedRecordsData[i]; //Change it to Account Id
sforce.connection.sessionId = '{!$Api.Session_ID}';
//Call webservice and get the base64 coded attachment data
const response = sforce.apex.execute("WS_ZipUtil", "getAttachmentById", {sfdcId: recordData.attachmentId});
const respObj = JSON.parse(response);
// If an error occures, break
if (respObj['status'] !== '200') {
reject(respObj ['error']);
return;
}
// If status is 200, mark this record as downloaded
// markAsDownloaded(recordData.q);
const fileData = respObj['data'];
//Add all attachments to the zip
for (let j = 0, l2 = fileData.length; j < l2; j++) {
zip.file(fileData[j]['Name'] + ' - ' + recordData.account + ' - ' + recordData.opportunity, fileData[j]['Body'].toString(), {base64: true});
}
resolve();
} catch (e) {
reject(e);
return;
}
}));
}
//Wait for all async calls and zip is finally generated and download it
Promise.all(promises).then(values => {
zip.generateAsync({type: "blob"}).then(function (content) {
saveAs(content, "download.zip");
btnElement.disabled = false;
});
});
let checkedRecords = this.getCheckedRecordsData();
sforce.connection.sessionId = '{!$Api.Session_ID}';
result = sforce.connection.query("select Downloaded__c from kognoz1__Invoice2__c");
records = result.getArray("records");
for (let i = 0, l = checkedRecords.length; i < l; i++){
records = true;
}
}
</script>
</body>
</html>
last 4 lines of javascript codes, i tried to update the field in backend if downloaded function is called. I am completely out of idea. i shall be grateful to you for any input. Thanks :)
<apex:includeScript value="/soap/ajax/47.0/connection.js"/>
<apex:includeScript value="/soap/ajax/47.0/apex.js"/>
<apex:includeScript value="{!$Resource.jszip}"/>
<apex:includeScript value="{!$Resource.FileSaver2}"/>
<html xmlns="https://www.w3.org/2000/svg" xmlns:xlink="https://www.w3.org/1999/xlink">
<head>
<apex:slds />
<style>
.displayBlock {
display: block;
}
.placeHolder {
margin-left: 50px;
margin-top: 50px;
Width: 50rem;
}
.Showall {
font-style: bold;
margin-top: 120px;
width: 100%;
}
.space {
font-style: italic;
font-size: 25px;
margin-left: 50px;
margin-top: 20px;
}
.slds-form-element__label slds-m-bottom_none {
font-size: 2rem;
}
.nishant {
font .
size: 1rem;
}
input.date {
cursor: pointer;
font-size: 18px;
margin: 12px;
padding: 4px;
width: auto;
text-align: center;
}
</style>
</head>
<body>
<apex:form title="form" styleClass="Showall" forceSSL="true" id="A">
<div class="slds-form-element">
<div class="slds-p-left_xx-large">
<label class="slds-checkbox_toggle slds-grid">
<span class="slds-form-element__label slds-m-bottom_none" style="font-size:.90rem"> Show All </span>
<input type="checkbox" name="checkbox-toggle-15" value="checkbox-toggle-15" aria-describedby="checkbox-toggle-15" onclick="getdata()" checked=""/>
<span id="checkbox-toggle-15" class="slds-checkbox_faux_container" aria-live="assertive" style="margin-left:15px">
<span class="slds-checkbox_faux"></span>
<span class="slds-checkbox_on">Enabled</span>
<span class="slds-checkbox_off">Disabled</span>
</span>
</label>
</div>
</div>
<div class="slds-grid slds-grid_align-space">
<div class="slds-p-top_xx-large">
<span>Date From
<apex:inputfield value="{!InvoiceInfo.kognoz1__Invoice_Date__c}" label="Start Date" id="datefrom"/>
</span>
</div>
<div class="slds-p-top_xx-large">
<span>Date To
<apex:inputfield value="{!InvoiceInfo.kognoz1__Invoice_Due_Date__c}" label="End Date"/>
</span>
</div>
<div class="slds-p-top_xx-large">
<apex:commandButton value="Search" action="{!display}" reRender="B"/>
</div>
</div>
<div class="slds-p-top_xx-large">
<apex:pageBlock >
<apex:pageBlockSection showHeader="false" id="B" columns="1" >
<apex:pageblocktable value="{!InvoiceList}" var="rs" id="A">
<apex:column >
<apex:facet name="header">
<input type="checkbox" id="selectAllCheckbox" onclick="selectAllCheckboxes(this)" />
<!--
<apex:inputcheckbox>
<apex:actionSupport event="onclick" onSubmit="return selectAllCheckboxes(this)" />
</apex:inputcheckbox>
-->
</apex:facet>
<apex:repeat value="{!rs.KI.attachments}" var="C">
<input type="checkbox" value="{!C.Id}" data-date="{!rs.KI.kognoz1__Invoice_Date__c}" data-account="{!rs.KI.kognoz1__Account__c}" data-opportunity="{!rs.KI.kognoz1__Opportunity__c}" data-Status="{!rs.KI.Downloaded__c}" Id="inputId" class="invoiceCheckBox" onClick="unselectSelectAllCheckboxes(this)" />
</apex:repeat>
</apex:column>
<apex:column value="{!rs.KI.kognoz1__Invoice_Date__c}" headerValue="DATE"/>
<apex:column value="{!rs.KI.kognoz1__Account__c}" headerValue="Account"/>
<apex:column value="{!rs.KI.kognoz1__Opportunity__c}" headerValue="Opportunity"/>
<apex:column headerValue="Files">
<apex:repeat value="{!rs.KI.attachments}" var="C">
<apex:outputLink value="https://c.cs101.content.force.com/servlet/servlet.FileDownload?file={!C.Id}&operationContext=S1" target="_blank" rel="nofollow">
{!C.name}
</apex:outputLink>
</apex:repeat>
</apex:column>
<apex:column value="{!rs.KI.Downloaded__c}" headerValue="Status"/>
</apex:pageblocktable>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:panelGrid columns="5" cellspacing="1" cellpadding="1">
<div class="slds-p-left_xx-large">
<apex:commandbutton value="Download" onclick="return downloadZip(this)" />
<apex:commandbutton value="Previous" action="{!previous}" disabled="{!DisablePrevious}" reRender="A,B"/>
<apex:commandbutton value="Next" action="{!next}" reRender="A,B"/>
</div>
<apex:actionStatus id="status" startText="Loading"/>
</apex:panelGrid>
</div>
</apex:form>
<script>
// select / unselect All
function selectAllCheckboxes(checkbox) {
var invoiceCheckBoxes = document.getElementsByClassName('invoiceCheckBox');
for(var i=0; i<invoiceCheckBoxes.length; i++){
invoiceCheckBoxes[i].checked = checkbox.checked;
}
}
// unselect selectAll-checkbox
function unselectSelectAllCheckboxes(checkbox) {
if(!checkbox.checked) {
var selectAllCheckBox = document.getElementById('selectAllCheckbox');
selectAllCheckBox.checked = false;
}
}
//Get the attachment ids of all selected checkboxes/records
function getCheckedRecordsData() {
const checkboxes = document.querySelectorAll('input[type=checkbox].invoiceCheckBox:checked');
let recordsData = [];
for (let i = 0, l = checkboxes.length; i < l; i++) {
recordsData.push({date: checkboxes[i].dataset.date, account: checkboxes[i].dataset.account, opportunity: checkboxes[i].dataset.opportunity, attachmentId: checkboxes[i].value, Status : checkboxes[i].Downloaded__c,});
}
return recordsData;
}
//Generating and download the zip files with all attachments
function downloadZip(btnElement) {
//Make btn disabled while generating zip with all attachments
btnElement.disabled = true;
const zip = new JSZip();
let promises = [];
let checkedRecordsData = this.getCheckedRecordsData();
if(!checkedRecordsData.length) {
btnElement.disabled = false;
return;
};
console.log('CHECK DATA', checkedRecordsData);
for (let i = 0, l = checkedRecordsData.length; i < l; i++) {
promises.push(new Promise((resolve, reject) => {
try {
//Get attachment id and set salesforce sessionId
const recordData = checkedRecordsData[i]; //Change it to Account Id
sforce.connection.sessionId = '{!$Api.Session_ID}';
//Call webservice and get the base64 coded attachment data
const response = sforce.apex.execute("WS_ZipUtil", "getAttachmentById", {sfdcId: recordData.attachmentId});
const respObj = JSON.parse(response);
// If an error occures, break
if (respObj['status'] !== '200') {
reject(respObj ['error']);
return;
}
// If status is 200, mark this record as downloaded
// markAsDownloaded(recordData.q);
const fileData = respObj['data'];
//Add all attachments to the zip
for (let j = 0, l2 = fileData.length; j < l2; j++) {
zip.file(fileData[j]['Name'] + ' - ' + recordData.account + ' - ' + recordData.opportunity, fileData[j]['Body'].toString(), {base64: true});
}
resolve();
} catch (e) {
reject(e);
return;
}
}));
}
//Wait for all async calls and zip is finally generated and download it
Promise.all(promises).then(values => {
zip.generateAsync({type: "blob"}).then(function (content) {
saveAs(content, "download.zip");
btnElement.disabled = false;
});
});
let checkedRecords = this.getCheckedRecordsData();
sforce.connection.sessionId = '{!$Api.Session_ID}';
result = sforce.connection.query("select Downloaded__c from kognoz1__Invoice2__c");
records = result.getArray("records");
for (let i = 0, l = checkedRecords.length; i < l; i++){
records = true;
}
}
</script>
</body>
</html>
last 4 lines of javascript codes, i tried to update the field in backend if downloaded function is called. I am completely out of idea. i shall be grateful to you for any input. Thanks :)