Hi We have two fields created for reporting and administrtion purpose.
- Product_Book_View_Count__c
- Product_Book_Download_Count__c
We track how many time a user is visiting the record and updating the 1st field Product_Book_View_Count__c,
Secondly we try to check how many time a user prints a VF page which is a PDF rendered. I have tried to implement both but first one worked as expected but the second one does not update the count rather it will take me to the vf page.
Please find the code snippet below.
<apex:page standardController="SG_ProductBook__c">
<apex:includeScript value="/soap/ajax/28.0/connection.js"/>
<script type="text/javascript">
sforce.connection.sessionId = '{!GETSESSIONID()}';
var object = new sforce.SObject('SG_ProductBook__c');
object.Id = "{!SG_ProductBook__c.Id}";
object.Product_Book_View_Count__c = {!SG_ProductBook__c.Product_Book_View_Count__c } + 1;
var result = sforce.connection.update([object]);
if(result[0].success != 'true'){
alert('Could not Update the Record View Tracking Information. \r\nError: ' + result[0].errors.message);
}
window.parent.location.href="/apex/SG_PrintBook?version=4&Id=a462p000000ZQT5AAO";
var object2 = new sforce.SObject('SG_ProductBook__c');
object2.Id = "{!SG_ProductBook__c.Id}";
object2.Product_Book_Download_Count__c = {!SG_ProductBook__c.Product_Book_Download_Count__c} + 1;
var result2 = sforce.connection.update([object]);
if(result2[0].success != 'true'){
alert('Could not Update the Record download Tracking Information. \r\nError: ' + result[0].errors.message);
}
</script>
</apex:page>
when I go into salesforce record detail page automatically it goes to the to the pdf even before I click on the PDF export custom lightning button.