1

I'm trying to retrieve the value from my javascript below that is inside the VisualForce Page.

 savingImage(imgData);

I need to transfer this value into my Apex controller to create the image to be store into the Document Folder.

I'm using the Developer Console to test out the Apex Class codes because I need a scheduler to get a screenshot of the page and store it into the Document folder.

I need a scheduler because the images are images of the salesforce chart and I'm using a scheduler to get a photo of the VisualForce Page and save it into the Document folder everyday at a certain time rather then I personally everyday go and get a screenshot of the page and upload the file.


VisualForce Page

<apex:page name="Custom_Dash_Board"  showHeader="true" sidebar="false" title="Custom DashBoard" renderAs="PDF" controller="SaveImage">

<html>
<div id='screenshot'>
<h1>Company Performance Dashboard</h1>

<div id='screenshot'>
 <h1>Combine Dashboard </h1>
 <img src='https://ap4.salesforce.com/servlet/servlet.ChartServer?rs=....' />
<img src='https://ap4.salesforce.com/servlet/servlet.ChartServer?rs=....' />' />
</div>



<script>
 html2canvas($('#screenshot'), {
    onrendered: function (canvas) {
        var imgData = canvas.toDataURL('image/png').split(',')[1];
        //SaveImage.saveImage('001i000000gDY4Z',imgData,handleResult); // 
        savingImage(imgData); // Calling action function which will call controller method
    }
});

function handleResult(result,event) {
 if(result.success) {
    alert('Screenshot attached');
  } else {
    alert('Error: '+result.errorMessage);
  }
}
</script>

<apex:form >
 <apex:actionFunction action="{!SavingImage}" name="savingImage" rerender="">

   <apex:param name="firstParam" assignTo="{!imageBody}" value="" />

</apex:actionFunction>
</apex:form>
</apex:page>

Apex Class Code

public with sharing class SaveImage {

String imageBody{get;set;}

public void SavingImage(){
Document docatt = new Document();
docatt.Name = 'Salesforce.png';
    docatt.Body = EncodingUtil.base64Decode(imageBody);
    docatt.FOLDERID = '00l6F001201p4Gi';
    docatt.IsPublic = true;
    docatt.ContentType = 'image/png';

    insert docatt;
 }
}

Error Message From Developer Console

Method does not exist or incorrect signature: [SaveImage].saveimage()

Error Message when I try to Save if I do not change the Apex Class Name

This schedulable class has jobs pending or in progress

Full Debug Log

39.0 APEX_CODE,FINEST;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WAVE,INFO;WORKFLOW,INFO
17:11:23.0 (548966)|USER_INFO|[EXTERNAL]|0056F00000746ij|jerome|Singapore Time|GMT+08:00
17:11:23.0 (582067)|EXECUTION_STARTED
17:11:23.0 (586612)|CODE_UNIT_STARTED|[EXTERNAL]|VisualForce View State
17:11:23.0 (5854703)|CODE_UNIT_FINISHED|VisualForce View State
17:11:23.0 (8003704)|EXECUTION_FINISHED

Error Message From Developer Console enter image description here

  • Did you tried using actionfunction ? – Muzammil Bajaria Apr 16 '17 at 12:43
  • actionfunction? I'm not familiar with it even after reading about it – Jerome AJJ Apr 16 '17 at 13:13
2

Try this code and I would suggest you to go through ActionFunction first before using it. Let me know if you have any query.

<script> 
      html2canvas($('#screenshot'), {
onrendered: function (canvas) {
    var imgData = canvas.toDataURL('image/png').split(',')[1];
   savingImage(imgData); // Calling action function which will call controller method
}
 });

 function handleResult(result,event) {
 if(result.success) {
  alert('Screenshot attached');
} else {
 alert('Error: '+result.errorMessage);
}
}
 </script>                   
// Use this action function inside <apex:form> of your visual force page(javascript function and actionfunction should be in same page)

 <apex:actionFunction action="{!savingImage}" name="savingImage" rerender="">

    <apex:param name="firstParam" assignTo="{!imageBody}" value="" />

</apex:actionFunction>

Apex Controller

public with sharing class SaveImage {
 String imageBody{get;set;}

public void savingImage(){
 Document docatt = new Document();
  docatt.Name = 'Salesforce.png';
        docatt.Body = EncodingUtil.base64Decode(imageBody);
        docatt.FOLDERID = '00l6F001201p4Gi';
        docatt.IsPublic = true;
        docatt.ContentType = 'image/png';

        insert docatt;
 }
}
  • I have updated the latest error into the post – Jerome AJJ Apr 19 '17 at 4:55
  • Try removing the commented line. SaveImage.saveImage('001i000000gDY4Z',imgData,handleResult); – Muzammil Bajaria Apr 19 '17 at 6:09
  • Please search for "SaveImage" method as you might have called this method that's why you are getting that error – Muzammil Bajaria Apr 19 '17 at 6:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.