function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Michael_MantouvalosMichael_Mantouvalos 

Export a dashboard's Image URL, so to be send via email with SingleEmailMessage

Hello Everyone, 

Is there a way to access the URL of a Dashboard's Image that is generated in Classic salesforce, so I can attach it to an email and send it to someone?

I would like to query the Dashboard that I need, then find its image URL , and then attach the URL to an Email body through SingleEmailMessage

Is this possible?

Thank you.

AnudeepAnudeep (Salesforce Developers) 
Hi Michael, 

You can only query the fields available in the dashboard. See Dashboard Object Metadata

If you want to get a dashboards Image see the following

Dashboard Image Resource

Here is a sample code for sending an email, in general, using singleEmailMessage
public class emailSending {
    public string toMail { get; set;}
    public string ccMail { get; set;}
    public string repMail { get; set;}
    
	public void sendMail(){
        Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
        string[] to = new string[] {toMail};
        string[] cc = new string[] {ccMail};
        
        email.setToAddresses(to);
        if(ccMail!=null && ccMail != '')
	        email.setCcAddresses(cc);
        if(repmail!=null && repmail!= '')
        	email.setInReplyTo(repMail);
        
        email.setSubject('Test Mail');
        
        email.setHtmlBody('Hello, <br/><br/>This is the test mail that you generated. <br/>The Email Id for which this mail was generated by '+toMail+'<br/><br/>Regards<br/> Developer');
        try{
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email });
        }catch(exception e){
            apexpages.addmessage(new apexpages.message(apexpages.severity.error,e.getMessage()));
        }
        
        toMail = '';
        ccMail = '';
        repMail = '';
    }
}
Let me know if it helps