Saturday, June 29, 2013

Generate JSON in Salesforce

I explore about JSON for generating pie chart in the site.I try this simple one, with hardcoded data.

1)Apex Controller to prepare the data
2)Visual force page to display the data in JSON

1) Apex controller
public class PieController {

     public String jsonString {get;set;}
    public PieController ()
      jsonString = prepareData();

    //Temp Method to prepare the Data
     private String prepareData()
       List<CompanyDetail > dtlObj = new List<CompanyDetail >();
       CompanyDetail c1 =new CompanyDetail('1','Samson',30);
       CompanyDetail c2=new CompanyDetail('2','Targus',35);
       CompanyDetail c3=new CompanyDetail('3','Swan',60);
       CompanyDetail c4=new CompanyDetail('4', 'Filla',30);
        return JSON.serialize(dtlObj);
     public class CompanyDetail {
       public String Name {get;set;}
       public Decimal share {get;set;}
       public String Id {get;set;}
       public CompanyDetail(String id,String Name,Decimal share){

2) Visual force page
<apex:page contenttype="application/x-JavaScript; charset=utf-8" controller="PieController" showheader="false" sidebar="false" standardstylesheets="false">


Finally the output,this is how the JSON page will look like


Friday, June 28, 2013

Using SyntaxHighlighter

Update:Sept 04 2015 (I m using
Notice how cool my code format here.Well I just install SyntaxHighlighter into this blog.

Let see what type of syntax do I get

Define in pre class

1) brush:html

<pre class="brush:html"><!--This is my html sample, in the pre class , I choose html-->
 <pre class="brush:html">My html code in here</pre>

<pre class="brush:sql">SELECT columnName FROM tableName </pre>

I refer to this :
1) 2)

Have a nice weekend