APEX JAVASCRIPT JSON Visual Force

Json in Apex class and Visualforce

Serializing JSON from Apex  Apex Class: public with sharing class jsonAccount { public string AccountNameList {get;set;}  public jsonAccount() {    list accList = [Select Id,Name From Account];     System.debug(JSON.serialize(accList));    AccountNameList = JSON.serialize(accList); } } Output:USER_DEBUG [2]|DEBUG|[{“attributes”:{“type”:”Account”,”url”:”/services/data/v24.0/sobjects/Account/001U0000002LdBXIA0″},”Id”:”001U0000002LdBXIA0″,”Name”:”GenePoint”},{“attributes”:{“type”:”Account”,”url”:”/services/data/v24.0/sobjects/Account/001U0000002LdBYIA0″},”Id”:”001U0000002LdBYIA0″,”Name”:”United Oil & Gas, UK”},{“attributes”:{“type”:”Account”,”url”:”/services/data/v24.0/sobjects/Account/001U0000002LdBZIA0″},”Id”:”001U0000002LdBZIA0″,”Name”:”United Oil & Gas,…

Read More
APEX Web Service

HTTP Callout from Apex Class

public class simpleHTTPCallOut {public simpleHTTPCallOut(ApexPages.StandardController controller) { } String ErrorMessage; public void Login() {  ErrorMessage=”;  final string baseUrl = ‘https://login.salesforce.com/‘;  final string username = ‘test@test.com’;  final string password = ‘test@123’;  Http h = new Http();  HttpRequest req = new HttpRequest();…

Read More
APEX Visual Force

Using Map In Your VF Pages

APEX CLASS:  public class TestMapController{          public map data {get;set;}          public TestMapController(){         data = new map();         for(Account acc: [Select Id, Name, (Select Id, Name, Email from Contacts), Phone from Account]){             integer count = data.get(acc.name);             if(count != null)                count++;            else               …

Read More
APEX Visual Force

Save an attachment in APEX

Example for save an attachment in APEX. APEX CODE: public class status{private final Applicant__c applicant;public Blob resume {get; set;}public String contentType {get; set;}public String fileName {get; set;} public status(ApexPages.StandardController stdController) {this.applicant=(Applicant__c)stdController.getRecord();}public PageReference saveApplication() {   try{        insert(applicant);                                          }catch(System.DMLException e){     …

Read More