Created
April 20, 2017 05:51
-
-
Save unidha/267218931a751d3596fdde4994ff31ca to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.