Skip to content

Instantly share code, notes, and snippets.

@unidha
Created April 20, 2017 05:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unidha/267218931a751d3596fdde4994ff31ca to your computer and use it in GitHub Desktop.
Save unidha/267218931a751d3596fdde4994ff31ca to your computer and use it in GitHub Desktop.
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
Copy link

shoaebk 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