0

Does anyone know of a good way to send a Visualforce chart through email? I was hoping that I could put them in a dashboard and send them out on a scheduled refresh, but I got a warning message saying that the component cannot be displayed in email. Also the dependence on javascript rules out a lot of other possibilities.

4 Answers 4

1

I don't think you will be able to do this using Visualforce charts, you will need to look into using an external library that allows this (e.g. Google Charts)

0

One way is to generate a PDF from VF page and send as an attachment. Please refer to this link on how to do it. Hope this will help you.

3
  • That is one of the issues with the charts using javascript. When you render the page as a pdf, the chart component won't be drawn.
    – martin
    Jun 10, 2015 at 6:37
  • 1
    There is a way if you can use google chart API. You can get the data in VF page from controller and pass as URL parameters to Google chart API. Example. You will get an image which can be embeded in a PDF with <apex:image> tag. I have tested it and can able to add it in a pdf.
    – Saroj Bera
    Jun 10, 2015 at 11:06
  • I had heard about the google chart api, but I was a bit hesitant to use it since I am in China and most things related to google are blocked (your link for example). However, since the salesforce asia/pacific servers are in Tokyo, I'm thinking that if I embed it in a pdf there, it might be okay.
    – martin
    Jun 10, 2015 at 16:03
0

By using this visualforce component you can send a visualforce chart/dashboard through email.

<apex:component access="global">
<apex:image value="https://instance.my.salesforce.com/servlet/servlet.ChartServer?[...]">
</apex:image>
</apex:component>

upload your image as document and use that url in component.

or you can use Static Resources to send Chart/Dashboard, for that you have to remember following things:

1 make your static resource Public by nature.

2 Save your chart's URl in your Static resources.

3 The spelling of the Static Resource match exactly to the path inside the ZIP file. Do let me know if this helps.

1
  • 1
    The chart I want to send is not currently an image. It is a Visualforce page that makes use of the <apex:chart> component. Is there a way that salesforce can draw the chart server-side and provide it as an image? Or is there a similar way to use an SOQL query and a bit APEX to generate a chart in salesforce that can be sent through email?
    – martin
    Jun 10, 2015 at 7:17
0

First make a VisualForce page like this (it will be rendered as pdf):

<apex:page controller="MyPdfTemplateController" showHeader="false" renderAs="pdf" >
<apex:image value="http://chart.apis.google.com/chart?cht=p&chd=s:Uf9a&chs=400x200&chl=January|February|March|April" width="400" height="200"/>        
</apex:page>

If chart image is not rendered then you need to allow access to google chart api. Go to Settings / Security Controls / Remote Site Settings and add http://chart.apis.google.com as new remote site.

This did the trick to me.

The apex:image code works also in VisualForce email templates.

More about google image chart api here: https://developers.google.com/chart/image/

Note that api is deprecated.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .