Develop On-Demand Business Applications Writing Apex and VisualForce Code

Description:
BISP is committed to provide BEST learning material to the beginners and advance learners. In the same series, we have prepared a complete end-to end Hands-on Beginner’s G ide !or Sales"orce. The doc ment !oc ses on #pe$ and %is al"orce code basics. #lso, we tal& abo t develop on-demand b siness applications. 'oin o r pro!essional training program and learn !rom e$perts.

History:
Version 0.1 0.1 Description Change Author nitial Dra!t Chandra Pra"ash #har$a 'e(ie)*1 A$it #har$a Publish Date 10th Aug %01& 10th Aug %01&

www.bispsol tions.com Page )

www.bisptrainigs.com

www.h(periong r .com

Contents
*ontents.......................................................................................................................... + #pe$ classes in Sales"orce............................................................................................. , +. -ptional de!inition modi!iers .s ch as virt al, abstract, and so on/.........................., ,. 0e1 ired 2 The &e(word class !ollowed b( the name o! the class............................., 3. -ptional e$tensions 2................................................................................................ , How to #dd an #pe$ *lass2........................................................................................... , #pe$ Triggers in Sales"orce............................................................................................. 4 Triggers 2................................................................................................................... 4 How to write Trigger in Sales"orce.com 2..................................................................5 How 6o %is al"orce Pages *ompare to S-*ontrols7........................................................8 *reating a %is al"orce *omponent..................................................................................8 9hat are * stom *omponents 2................................................................................8 :sing * stom *omponents in a %is al"orce Page2..................................................); How to 6e!ining * stom *omponents 2...................................................................); 9hat is %is al"orce.................................................................................................... )) 9h( se %is al"orce 2............................................................................................. )+ How To *reate %is al"orce Page ............................................................................ )+ ............................................................................................................................... )3 :sing the %is al"orce *omponent <ibrar( ....................................................................)3 -verriding an E$isting Page with a %is al"orce Page....................................................)4 0edirecting to a Standard -b=ect <ist Page...................................................................)> :sing Inp t *omponents in a Page................................................................................ )?

www.bispsol tions.com Page +

www.bisptrainigs.com

www.h(periong r .com

Apex classes in #alesForce
In Sales"orce "orce.com #pe$ *ode is an ob=ect oriented programming lang age that allows developers to develop on-demand b siness applications on the "orce.com plat!orm. De!ine a class+ speci!y the !ollo)ing : ). #ccess modi!iers 2  @o can se access modi!iers p blic or global in the declaration o! a top-level class.  6o not se an access modi!ier in the declaration o! an inner class. +. -ptional de!inition modi!iers .s ch as virt al, abstract, and so on/ ,. 0e1 ired 2 The &e(word class !ollowed b( the name o! the class 3. -ptional e$tensions 2 "ollowing s(nta$ !or de!ining classes2 private A p blic A global Bvirt al A abstract A with sharing A witho t sharing A .none/C class *lassDame Bimplements Inter!aceDame<ist A .none/C Be$tends *lassDame A .none/C E FFBod( o! the class G

Ho) to Add an Apex Class:
#etup H De(eloper H Apex classes, there is man( option. (o can see below. De(eloper Console : In Sales!orce.com developer *onsole is an integrated development environment with a collection o! tools (o can se to create, deb g, and test applications in (o r Sales"orce organiIation. ,e) : *lic& on Dew b tton open new page on this page (o can write #pe$ code here. -enerate Fro$ W#D. : To access the "orce.com 9eb service, (o need a 9eb Service 6escription <ang age .9S6</ !ile. The 9S6< !ile de!ines the 9eb service that is available to (o . @o r development plat!orm ses this 9S6< to generate an #PI to access the "orce.com 9eb service it de!ines. 'un All /ests : *lic& on 0 n #ll tests b tton !or r n all !iles. #chedule Apex : (o can sched le #pe$ code b( sing #chedule Apex b tton.

www.bispsol tions.com Page ,

www.bisptrainigs.com

www.h(periong r .com

"or create new #pe$ code clic& on Dew b tton . *lic& on ,e) b tton, #!ter that open new web page on this page #pe$ *ode editor is available. (o can see below. write here #pe$ *lass a!ter then clic& on #a(e b tton.

www.bispsol tions.com Page 3

www.bisptrainigs.com

www.h(periong r .com

#chedule Apex : Sched le an #pe$ class that implements the JSched lableJ
inter!ace to be a tomaticall( e$ec ted on a wee&l( or monthl( interval. *lic& on #chedule Apex b tton.

Apex /riggers in #alesForce
/riggers :
#pe$ can be invo&ed thro gh the se o! triggers. # trigger is e$ec tes be!ore or a!ter the !ollowing t(pes o! operations2  insert  pdate  delete  psert  merge  ndelete /riggers can be di(ided into t)o types : Be!ore triggers can be sed to pdate or validate record val es be!ore the( are saved to the database. Triggers can be sed to access !ield val es that are set b( the database, "or E$ample recordJs Id or last:pdated !ield, and to a!!ect changes in other records, s ch as logging into an a dit table or !iring as(nchrono s events with a 1 e e. /rigger Context Variables : www.bispsol tions.com Page 4 www.bisptrainigs.com www.h(periong r .com

Variable isInsert is:pdate isE$ec ting

is6elete isBe!ore is#!ter is:ndelete

new newKap old oldKap siIe

0sage 0et rns tr e i! this trigger was !ired d e to an insert operation, !rom the Sales"orces ser inter!ace, #pe$, or the #PI. 0et rns tr e i! this trigger was !ired d e to an pdate operation, !rom the Sales"orce ser inter!ace, #pe$, or the #PI. 0et rns tr e i! the c rrent conte$t !or the #pe$ code is a trigger, not a %is al"orce page, a 9eb service, or an e$ec teanon(mo s./ #PI call. 0et rns tr e i! this trigger was !ired d e to an delete operation, !rom the Sales"orce ser inter!ace, #pe$, or the #PI. 0et rns tr e i! this trigger was !ired be!ore an( record was saved. 0et rns tr e i! this trigger was !ired a!ter all records were saved. 0et rns tr e i! this trigger was !ired a!ter a record is recovered !rom the 0ec(cle Bin .that is, a!ter an ndelete operation !rom the Sales"orce ser inter!ace, #pe$, or the #PI./ 0et rns a list o! the new versions o! the s-b=ect records. # map o! I6s to the new versions o! the s-b=ect records. 0et rns a list o! the old versions o! the s-b=ect records. # map o! I6s to the old versions o! the s-b=ect records. The total n mber o! records in a trigger invocation, both old and new.

Ho) to )rite /rigger in #alesForce.co$ :
#etup H De(elop H Apex /riggers, *lic& on De(eloper Console b tton. open new web page. @o can see below. "or create #pe$ Trigger clic& on File H ,e) H Apex /rigger.

www.bispsol tions.com Page 5

www.bisptrainigs.com

www.h(periong r .com

#!ter that open pop p window in this window, 9rite Trigger name and select -b=ect class .which (o need to bind with trigger/ then clic& on s bmit b tton. Then (o can see new page !or write new trigger.

#!ter 9rite trigger , go to File men and clic& on #a(e see below . also (o se C/'. 1 # b( sing &e(board. ,ote : "or nderstanding #pe$ *lasses or #pe$ Trigger (o can see here. E$ample , see below .

2xa$ple : 9rite ape$ code !or a tomaticall( increasing +L on the s bmit !ees !or ever( st dent. #tep 1 : *reate an( c stom ob=ect tab. "or E$ 2 *ollege (o can see below.

www.bispsol tions.com Page >

www.bisptrainigs.com

www.h(periong r .com

#tep % : #!ter then go to adding #pe$ code, #etup H De(eloper H Apex classes+ clic& on ,e) b tton. then write here #pe$ code.

#tep & : #!ter write #pe$ classes , 9rite #pe$ Trigger *lic& on Apex /rigger !or write #pe$ Trigger.

www.bispsol tions.com Page ?

www.bisptrainigs.com

www.h(periong r .com

#tep 3 : #!ter that Save !ees, then see !ees increase +L .

Ho) Do VisualForce Pages Co$pare to #4Controls5
S-*ontrols, is older "orce.com technolog( that has now been s perseded b( %is al"orce, still ! nction on "orce.com. @o can contin e to se e$isting S-*ontrols, b t restrictions are being placed on creating new ones.

Creating a VisualForce Co$ponent
Sales!orce.com provides a librar( o! standard, pre-b ilt components, s ch as Mape$2page render#sNOpd!OH, Mape$2tabPanel H and Mape$2dataTableH, that can be sed to develop %is al"orce pages. In addition, (o can b ild (o r own c stom components to a gment this librar(.

What are Custo$ Co$ponents :
In c stom components (o can re se that method several times in a program, (o can encaps late a common design pattern in a c stom component and then re se that component several times in one or more %is al"orce pages.

www.bispsol tions.com Page 8

www.bisptrainigs.com

www.h(periong r .com

2xa$ple, I! (o want to create a Emplo(ee list sing %is al"orce pages. Each Emplo(ee record in the list has its own border. 0ather than repeating the %is al"orce mar& p re1 ired !or displa(ing ever( Emplo(ee record in the list. -nce de!ined, standard components s ch as Mape$2related<istH or Mape$2dataTableH .

0sing Custo$ Co$ponents in a VisualForce Page:
*reate a new c stom component named record6ispla(. Mape$2page H Mape$2pageBloc& titleNOEmplo(ee <istO H MbH 9elcome 2MFbH EPQ:ser."irstDameG Mape$2detail FH MFape$2pageBloc&H MFape$2pageH

Ho) to De!ining Custo$ Co$ponents :
#etup H De(elop H Co$ponents, *lic& on ,e) b tton.

#tep 1 : Enter <abel Dame then write %is al"orce *omponent a!ter then clic& on #a(e b tton.

www.bispsol tions.com Page );

www.bisptrainigs.com

www.h(periong r .com

#tep % : #!ter that create new %is al"orce page and write here some cod (o can see below.

What is VisualForce
%is al"orce is !ramewor& that allows developers to b ild re!ined, c stom ser inter!aces that can be hosted nativel( on the "orce.com plat!orm. The %is al"orce !ramewor& incl des a tag-based mar& p lang age, similar to HTK<. In %is al"orce page (o can se html code, 'avaScript, *SS, #=a$, "lesh. 6evelopers can se %is al"orce to create a %is al"orce page de!inition. # page de!inition consists o! two primar( elements2 - %is al"orce mar& p. - # %is al"orce controller. VisualForce 6ar"up :4 %is al"orce mar& p consists o! %is al"orce tags, HTK<, 'avaScript, or an( other 9ebenabled code embedded within a single <apex: page> tag. The mar& p de!ines the ser inter!ace components that sho ld be incl ded on the page, and the wa( the( sho ld appear. VisualForce Control :4 # %is al"orce controller is a set o! instr ctions that speci!( what happens when a ser interacts with the components speci!ied in associated %is al"orce mar& p, s ch as when a ser clic&s a b tton or lin&.

www.bispsol tions.com Page ))

www.bisptrainigs.com

www.h(periong r .com

Why use VisualForce :
- To create c stom inter!aces. - To b ild wiIards. - To de!ine c stom navigation patterns.

Ho) /o Create VisualForce Page
*lic& on #etup H de(elop H Pages Then *lic& on Dew b tton.

www.bispsol tions.com Page )+

www.bisptrainigs.com

www.h(periong r .com

#tep 1 :

#!ter Saving this page. clic& on this icon to view Home page.

I! (o are getting error !or view page, solve this problem b( !ollowing some steps.Given below. www.bispsol tions.com Page ), www.bisptrainigs.com www.h(periong r .com

*lic& on #etup H 6anage 0sers H 0sers then clic& on Edit lin& b tton !or edit ser settings.

Then (o can !ind 6evelopment Kode and chec&ed chec& bo$ then clic& on save b tton. #!ter then (o can clic& on view icon that time, there is %is al"orce to as& (o to create new page beca se this page is open in development mode.

#econd type o! create VisualForce page : go to web browser t(pe :0 <, (o can see below. E$ 2 Http2FF Sales"orce lin& a!ter loginFape$FPage Dame

0sing the VisualForce Co$ponent .ibrary
%is al"orce Mape$2pageHMFape$2pageH tag is se mandator(, tag m st be placed at start and end o! all %is al"orce mar& p. and also %is al"orce s pports all html tag. "or e$ample 2 Mimg srcNO OH, MtableHMtrHMtdHMFtdHMFtableH, Mmar1 eeHMFmar1 eeH etc. Ho) to use VisualForce Co$ponent .ibrary : ' st go to create new page. "or e$ample I will create E$ample+ . @o can see below. www.bispsol tions.com Page )3 www.bisptrainigs.com www.h(periong r .com

9hen (o clic& on *omponent 0e!erence lin& (o can see new web page. -n this web page all *omponent with s(nta$ are available, which *omponent (o want to add ' st write in code window. see below. #nd also see how to se !ra$e in VisualForce page .

7(erriding an 2xisting Page )ith a VisualForce Page
I! (o need to change the !ormat o! an e$isting page, s ch as the standard acco nt detail page. #ll the in!ormation displa(s on a single page. I! thereJs a lot o! in!ormation, (o might end p doing a lot o! scrolling. :sing %is al"orce in a page (o can ma&e each section.Tab/ !or an acco nt displa( in a tab. ). "irstl(, *reate a new %is al"orce page sing the 1 ic& !i$. Fape$FPageDame www.bispsol tions.com Page )4 www.bisptrainigs.com www.h(periong r .com

"or E$ample 9e create this page https2FFc.ap).vis al.!orce.comFape$F-verrding

+. *reate -verriding page. ,. 6elete E$isting code. and paste it below code. 3. See below code.

www.bispsol tions.com Page )5

www.bisptrainigs.com

www.h(periong r .com

'edirecting to a #tandard 7b8ect .ist Page
In Sales!orce.com, b ttons or lin&s that navigate a ser to a standard tab, (o can redirect the content to present a list o! standard ob=ects. *reate a %is al"orce page with the !ollowing mar& p 2 "ollowing code ses command b tton, see below.

www.bispsol tions.com Page )>

www.bisptrainigs.com

www.h(periong r .com

#!ter *lic& on this b tton (o can see page redirect #cco nt page. (o can see below.

0sing nput Co$ponents in a Page
In %is al"orce (o can se the Mape$2!ormH tag with one or more inp t components and a Mape$2command<in&H or Mape$2commandB ttonH tag to s bmit the !orm. /he input co$ponent tag :  Mape$2inp t*hec&bo$H  Mape$2inp t"ieldH  Mape$2inp tSecretH  Mape$2inp tTe$tH  Mape$2inp tTe$tareaH  Mape$2o tp t"ieldH  Mape$2o tp tTe$tH  Mape$2select*hec&bo$esH  Mape$2select<istH  Mape$2select0adioH

www.bispsol tions.com Page )?

www.bisptrainigs.com

www.h(periong r .com

www.bispsol tions.com Page )8

www.bisptrainigs.com

www.h(periong r .com

Sign up to vote on this title
UsefulNot useful

Master Your Semester with Scribd & The New York Times

Special offer for students: Only $4.99/month.

Master Your Semester with a Special Offer from Scribd & The New York Times

Cancel anytime.