You need to sign in to do that
Don't have an account?
manoj6492
Wrapper class for beginners
Hi,
I am a trainee in sales force development ,When i was trying to find examples for wrapper class i couldnt find much most of them were based on visualforce.I have posted a code for better understanding about wrapper class for the beginners.
@RestResource(urlMapping='/MyAccount/*') global with sharing class wrapper { @HttpGet global static string MyAccount() { RestRequest req = RestContext.request; RestResponse res = RestContext.response; list<Account> acc = [Select name ,Id, (Select name, Email from Contacts)From Account where ActiveStatus__c=true]; list<Accountw> aw = new list<Accountw>(); for(Account ac :acc) { system.debug('ac1'); list<ContactW> con= new list<ContactW> (); system.debug('newlis:'+con); for(contact c :ac.Contacts) { system.debug('contact>>'+c); contactW c1 = new contactW(c.name,c.email); con.add(c1); } Accountw a = new Accountw(ac.Id,ac.name,con); aw.add(a); }system.debug('the list :'+Json.serialize(aw)); return Json.serialize(aw); } global class Accountw { string Ids{get;set;} string Name1{get;set;} list<contactW> con{get;set;} Accountw(String id,string name,list<contactW> con1) { Ids=id; Name1=name; con= con1; } } class contactW { string cname{get;set;} string Email1{get;set;} contactW(string name ,string email) { cname = name; Email1 = email; } } }
I this code i have used REST ,JSON and Wrapper class
Adding few more links for the benefit.
http://wiki.developerforce.com/page/Wrapper_Class
http://www.interactiveties.com/blog/2012/visualforce-wrapper-class.php
http://richardvanhook.com/2009/08/03/visualforce-pagination-with-apex-lang/
http://www.blacktabgroup.com/keeping-tabs/posts/2012/august/forcecom-development-using-wrapper-classes-to-access-cross-object-data.aspx
http://boards.developerforce.com/t5/General-Development/Reg-Wrapper-Classes-in-Apex-Programming/td-p/303681
http://vck1.blogspot.in/2011/05/wrapper-class-in-apexvisual-force.html
Regards,
Ashish