Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
global class VFChart_Server{
public Opportunity opportunity {get;set;}
public VFChart_Server(ApexPages.standardController std){
opportunity=(Opportunity)std.getRecord();
}
public List<PieWedgeData> getPieData() {
List<PieWedgeData> data = new List<PieWedgeData>();
data.add(new PieWedgeData('Jan', 30));
data.add(new PieWedgeData('Feb', 15));
data.add(new PieWedgeData('Mar', 10));
data.add(new PieWedgeData('Apr', 20));
data.add(new PieWedgeData('May', 20));
data.add(new PieWedgeData('Jun', 5));
return data;
}
// Wrapper class
public class PieWedgeData {
public String name { get; set; }
public Integer data { get; set; }
public PieWedgeData(String name, Integer data) {
this.name = name;
this.data = data;
}
}
@RemoteAction
global static void saveChartAsAttachment(String oppId,String attachmentBody){
system.debug('@@@saveChartAsAttachment oppId ='+ oppId);
List<Attachment> listAttachment =[Select Name,Id,Body from Attachment Where ParentId=:oppId];
Attachment att;
if(listAttachment.size()>0){
att =listAttachment[0];
att.Body = EncodingUtil.base64Decode(attachmentBody);
update att;
}
else{
att = new Attachment();
att.Name='spiderChart_VF';
att.ParentId=oppId;
att.ContentType='image/png';
att.Body = EncodingUtil.base64Decode(attachmentBody);
insert att;
}
}
}
@shoaebk

This comment has been minimized.

Copy link

commented May 22, 2017

Thanks for sharing this code. It's very helpful.
Can you please guide me how to use the saved attachment via apex and render it in Visualforce.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.