Sie sind auf Seite 1von 12

Salesforce Case Study Based Learning Force.com Sites & Site.

com

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 !"ide #or SalesForce. The doc"ment #oc"ses on case st"d$ based learning #or Force.com site and Site.com.%oin o"r pro#essional training program and learn #rom e&perts.

History:
Version Description Change 0.1 Initial Draft 0.1 %e&ie'(1 Author Chandra Prakash har!a A!it har!a Publish Date 10th "an #01$ 1#th "an #01$

www.bispsolutions.com

www.bisptrainigs.com

www.hyperionguru.com

Page 1

Question 1: How can I create a page in site.com to search data dynamically and display it in table?
Solution: Step 1: Firstly create Apex code for search data.

Code :
public with sharing class accsearchvalue { public list <account> acc {get;set;} public string searchstring {get;set;} public accsearchvalue(ApexPages.StandardController controller { } public void search( { string search!uer"#$select na%e&id 'ro% account where na%e li(e )$*$+searchs tring+$*)$ ,i%it -.$; acc# /atabase.!uer"(search!uer" ; } public void clear( { acc.clear( ; } }

Step 2: Then create VisualForce page . you can see below.

www.bispsolutions.com

www.bisptrainigs.com

www.hyperionguru.com

Page 2

Code : <apex:page standardController !account! extensions !accsearch"alue!# <apex:for$ # <apex:inputText "alue !%&searchstring'! label !(nput!)# <apex:co$$and*utton "alue !+earch records! action !%&search'!)# <apex:co$$and*utton "alue !Clear records! action !%&search'!)# <apex:page*loc, title !+earch -esult!# <apex:pagebloc,Table "alue !%&acc'! "ar !a!# <apex:colu$n # <apex:outputlin, "alue !https:))ap1.salesforce.co$)%&a.id'!#%&a..a$e'<)apex:outputlin,# <)apex:colu$n# <apex:colu$n "alue !%&a.id'!)# <)apex:page*loc,Table# <)apex:page*loc,# <)apex:for$# <)apex:page# Step 3 : Then go to Setup # e!elop # Sites/ Clic, on .ew button for add new site .

Question 2: Create a dependent input te"t in #isual$orce page.


www.bispsolutions.com www.bisptrainigs.com www.hyperionguru.com Page 0

(n VisualForce page ( ha"e 2 input texts/ if ( write anything in input text1/ auto$atically inputtext2 co$es "isible/ ( need pic,list functionality in1between fields in VisualForce page how can ( get this. Solution :

Code : <apex:page controller !2artial2age-efreshController!# <apex:for$ id !for$!# <apex:page*loc, title !3ser (nput! id !the2age*loc,!# <apex:page*loc,section colu$ns !2!# <apex:inputText "alue !%&inputValue1'! id !theText(nput1! label !(nput 1! tabindex !1!# <&11 action support allows you to add e"ent handlers onto VF co$ponents that don4t nor$ally support the$ the !re-ender! attribute can point to any VF co$ponent on the page 11# <apex:action+upport re-ender !refresh! e"ent !on,eyup! )# <)apex:inputText# <&11 the !rendered! attribute tells the VF page renderer whether or not to generate the 5T67 for this co$ponent 11# www.bispsolutions.com www.bisptrainigs.com www.hyperionguru.com Page 8

<apex:output2anel id !refresh!# <apex:pagebloc,section rendered !%&79.:inputValue1;#<'!# <apex:inputText "alue !%&inputValue2'! id !theText(nput2! label !(nput 2! rendered !true! tabindex !2!)# <)apex:pagebloc,section# <)apex:output2anel# <)apex:page*loc,section# <)apex:page*loc,# <)apex:for$# <)apex:page# %pe" Code :
public class PartialPage0e'reshController{ public String input1alue2 {get;set;} public String input1alue- {get;set;} public String get3nput1alue2( { return null; } public String get3nput1alue-( { return null; } }

Question 3: How to &ass parameters while clic' image in my page?


( ha"e re=uire$ent clic,ing i$age in VF page then it should display list of records .5ow to pass para$eters in clic,ing on ($age in VF and Apex> Solution: Controller Class : public class i$agepassValue% public +tring sa"e % get? set? ' public (nteger @ % get? set? ' public i$agepassValue:; % @ <? ' public 2age-eference Test@:; % +tring str@ Apex2ages.current2age:;.get2ara$eters:;.get:4@4;? if :str@ & null; % this.@ (nteger.ValueAf:str@;? ' return null? ' '

www.bispsolutions.com

www.bisptrainigs.com

www.hyperionguru.com

Page B

#isual $orce &age:

#isual$orce Code : <apex:page controller !i$agepassValue!# <apex:for$ id !-(C!# <br )#<br )#<br )# <h1#2ass para$eters while clic, i$age<)h1# <hr )# <apex:co$$and7in, action !%&Test@'! rerender !-(C! # Aut put Value :<apex:para$ na$e !@! "alue !%&@ D 1'! )# <apex:outputText "alue !%&@'!)#<br)# <apex:i$age id !the($age! "alue !)i$g)logo.gif! width !22<! height !BB!)#<)apex:co$$and7in,# <hr )# <)apex:for$# <)apex:page#

www.bispsolutions.com

www.bisptrainigs.com

www.hyperionguru.com

Page E

Question (: How to ma'e image as lin' in #isual$orce?


Solution : <a href !)apex)"fpage!#<apex:i$age id !new($age! "alue !%&F-esource.$ybti$g'! )#<)a#

Question ): How to Change *ime o+ ate,*ime $ield.


&roblem : Ghen ( a$ trying to sa"e the Cate)Ti$e Field of an AbHect/ the ti$e should sa"ed by round off to so$e fixed ti$e e.g. when ( a$ selecting date as 2)2E)2<18 the ti$e auto$atically co$es as the present ti$e i.e. 1<:8E A6. *ut ( want to sa"e it as 11:<< A6 after clic,ing the sa"e button in database/ that is when the ti$e is between 1<:0< A6 to 11:<< A6 it should get sa"ed as 11:<< A6. Also if ti$e is between 1<:<< A6 to 1<:0< A6 then it gets sa"ed as 1<:0< A6 in database. 5ow should in proceed. Solution:

%pe" Class: public class +o$eClass% public static "oid setTi$e:-eser"ationIIcJK sos;% for:-eser"ationIIc so : sos;% if:so.*oo,ingITi$eICateIIc null ;% continue? ' if:so.*oo,ingITi$eICateIIc.$inute:; # 0< ;% so.*oo,ingITi$eICateIIc so.*oo,ingITi$eICateIIc.add6inutes:E< 1 so.*oo,ingITi$eICateIIc.$inute:;;.add+econds:11 L so.*oo,ingITi$eICateIIc.second:; ;? ' else % so.*oo,ingITi$eICateIIc so.*oo,ingITi$eICateIIc.add6inutes:0< 1 so.*oo,ingITi$eICateIIc.$inute:;;.add+econds:11 L so.*oo,ingITi$eICateIIc.second:; ;? ' ' '' %pe" *rigger : www.bispsolutions.com www.bisptrainigs.com www.hyperionguru.com Page M

trigger changeIdate on -eser"ationIIc :before insert; % +o$eClass.setTi$e:trigger.new;? '

Question -: $orm reset a+ter clic'ing a button?


&roblem : ( ha"e two button are there first button is to reset and second button is to show list .Ghen ( clic, on the reset button before clic, the list it is reset the for$ when ( clic, the reset button after clic,ing the list it is not wor,ing. Solution :

#isual$orce Code : <apex:page standardController !account! extensions !accsearch"alue!# <apex:for$ # <apex:inputText "alue !%&searchstring'! label !(nput!)# <apex:co$$and*utton "alue !-eset! onclic, !this.for$.reset:;?return false?! )# <apex:co$$and*utton "alue !Nuote 7ist! rerender !redrawArea! )# <)apex:for$# <apex:page*loc, id !redrawArea!# %&searchstring' <)apex:page*loc,# <)apex:page#

Question -: .pdate custom ob/ect using #isual$orce page.


2roble$: .eed to update date field current date after +a"e date . Controller Class: www.bispsolutions.com www.bisptrainigs.com www.hyperionguru.com Page O

public with sharing class update4b5ect{ public ,ist<60Products77c> values; public Page0e'erence update4b5ect( { values#8S9,9C: 0e'reshed7/ate77c ;04< 60Products77c =; 'or (60Products77c s >values { s.0e'reshed7/ate77c #/ate.toda"( ; } update values; return null; } }

#isual$orce &age: <apex:page showheader !false! controller !updateAbHect! sidebar !false!# <apex:for$ # <apex:page*loc, title !3pdate Cate Field!# <apex:page*loc,+ection # <apex:co$$and*utton action !%&updateAbHect'! "alue !Clic, here to 3pdate Cate !)# <)apex:page*loc,+ection# <)apex:page*loc,# <)apex:for$# <)apex:page#

Question 0: %dd pic'list !alue

ynamically.

&roblem : Ge want to add Cyna$ically pic,list "alue in VisualForce page. Solution : Step 1: Create custo$ pic,list "alue in custo$ obHect. Step 2: Grite class controller . you can see below. public class dyna$icpic,list % public +tring city%get? set?' public 7ist<+electAption# getcityna$es:; % 7ist<+electAption# options new 7ist<+electAption#:;? 7ist<Cyna$ic2ic,listIIc# citylist new 7ist<Cyna$ic2ic,listIIc#:;? citylist J+elect (d/ 2ic,listValueIIc F-A6 Cyna$ic2ic,listIIc K? options.add:new +electAption:411.one114/411.one114;;? for :(nteger H <?H<citylist.siPe:;?HDD; % options.add:new +electAption:citylistJHK.2ic,listValueIIc/citylistJHK.2ic,listValueIIc;;? ' return options? ' public +tring newpic,list"alue%get? set?' public "oid sa"erec:; % Cyna$ic2ic,listIIc newrec new Cyna$ic2ic,listIIc:2ic,listValueIIc newpic,list"alue;? insert newrec? www.bispsolutions.com www.bisptrainigs.com www.hyperionguru.com Page Q

newpic,list"alue .377? ' ' Step 3 : Create VisualForce page . see below.

#isual$orce &age Code: <apex:page controller !dyna$icpic,list! sidebar !false! # <apex:for$ # <apex:section5eader title !Cyna$ic 2ic,list! subtitle !-eusable code!)# <apex:pagebloc, # <apex:page*loc,+ection title !Cyna$ic pic,list! colu$ns !1!# <apex:pagebloc,section(te$ # www.bispsolutions.com www.bisptrainigs.com www.hyperionguru.com Page 1<

<apex:outputlabel "alue !City! for !"alues! )# <apex:select7ist "alue !%&city'! siPe !1! id !"alues!# <apex:action+upport e"ent !onchange! re-ender !new"alue! )# <apex:selectAptions "alue !%&cityna$es'!)# <)apex:select7ist# <)apex:pagebloc,section(te$# <apex:outputpanel id !new"alue!# <apex:outputpanel rendered !%&city 411Ather114'!# <di" style !position:relati"e?left:MBpx?!# <apex:outputlabel "alue !.ew "alue! for !new"al! )# <)di"# <)apex:outputpanel# <strong#9nter City .a$e Rnbsp?Rnbsp?<)strong#<apex:inputText "alue !%& newpic,list"alue'! id !new"al1!)# <apex:co$$and*utton action !%&sa"erec'! "alue !Clic, 5ere +a"e City!)# <)apex:outputpanel# <)apex:pagebloc,section# <)apex:pagebloc,# <)apex:for$# <)apex:page#

Question 1: 2et the categories assigned to Idea 3ones.


&roblem : ( a$ building a custo$ VF page to show the ideas. ( want to get the list of categories that are assigned to an idea Pone. For ex: ( ha"e created 0 Pones: Pone A/ Pone */ Pone C for ideas. ( ha"e assigned Categories Categories 1/ 2/ 0 to Pone A/ Categories 8/ B/ E to Pone */ Categories 0/ B/ E to Pone C. (f ( go to standard (deas tab/ so$ehow +alesForce could show the correct list of categories drop down for each Pone. whereas ( don4t find any option in Apex to =uery the list of assigned categoriPed for each Pone. Solution:

www.bispsolutions.com

www.bisptrainigs.com

www.hyperionguru.com

Page 11

www.bispsolutions.com

www.bisptrainigs.com

www.hyperionguru.com

Page 12

Das könnte Ihnen auch gefallen