New Batch#100 (10th Nov 2021) - Salesforce Admin + Dev Training (WhatsApp: +91 - 8087988044) :https://t.co/p4F3oeQagK

Thursday, 19 July 2012

Passing parameters between visualforce pages

Setting Parameters:
*From VF Page:
<apex:outputLink value="/apex/page4">click<apex:param name="EN" value="Success"/></apex:outputLink>
*From Page Reference:
PageReference nextpage = new PageReference('/apex/Page4?EN='+EmployeeName+'&EN2='+EmployeeName2);
-To pass more than one parameter We should use & symbol inbetween.
*  PageReference nextpage = new PageReference('/apex/Page4');
    nextpage.getParameters().put('En',EmployeeName);
    nextpage.getParameters().put('En2',EmployeeName2);
- We can use multiple put statements to pass multiple parameters.
To pass the parameters between the VF pages which have same controllers:
*No need to pass any parameters only the thing is that we should not  use nextpage.setRedirect(True);
*For this we need two VF pages and one controller.
 *VF page1:
<apex:page controller="customcontroller1">
<apex:form >
   Name<apex:inputtext id="inpEmployeeName" value="{!EmployeeName}"/><br/>
   <apex:CommandButton value="Next" action="{!next}" id="cmdNext" />
</apex:form>
</apex:page>

*VF page2:
<apex:page controller="customcontroller1">
   .The employee name is {!EmployeeName}
</apex:page>

*APEX Controller1:
public class customcontroller1 {

    public PageReference next() {
        PageReference nextpage = new PageReference('/apex/Page2');
        nextpage.setRedirect(False);//By default it is false, we should not make it true

        //if we make it true values will be vanished while we are navigating from one 
        //page to another page
        return nextpage;      
    }
    public String EmployeeName { get; set; }
}


To pass the parameters between the VF pages which have different controllers:
*For this we need two VF pages and two controllers.
*VF page1:
<apex:page controller="customcontroller1">
<apex:form >
   First<apex:inputtext id="inpEmployeeName" value="{!EmployeeName}"/><br/>
   Second<apex:inputtext id="inpEmployeeName2" value="{!EmployeeName2}"/><br/>
   Second<apex:inputtext id="inpEmployeeName3" value="{!EmployeeName3}"/><br/>
   <apex:CommandButton value="Next" action="{!next}" id="cmdNext" >     
   </apex:commandButton>
  <!-- <apex:outputLink value="/apex/page4">click<apex:param name="EN" value="{!EmployeeName}"/></apex:outputLink>-->
</apex:form>
</apex:page>
*APEX Controller1:
public class customcontroller1 {

    public String EmployeeName3 { get; set; }

    public String EmployeeName2 { get; set; }

    public PageReference next() {
        //PageReference nextpage = new PageReference('/apex/Page4?EN='+EmployeeName+'&EN2='+EmployeeName2);
        PageReference nextpage = new PageReference('/apex/Page4');
        nextpage.getParameters().put('En',EmployeeName);
        nextpage.getParameters().put('En2',EmployeeName2);
        nextpage.getParameters().put('En3',EmployeeName3);

        return nextpage.setRedirect(True); //Note that setRedirect method is used here
    }


    public String EmployeeName { get; set; }
}

*VF page2:
 <apex:page controller="customcontroller2">
   The employee name is {!EmployeeName}<br/>
   The employee name is {!EmployeeName2}<br/>
   The employee name is {!EmployeeName3}
   <!--{!$CurrentPage.parameters.EN}
   <apex:detail subject="{!$CurrentPage.parameters.EN}"/>-->
</apex:page>

*APEX Controller2:
public class customcontroller2 {

    public String EmployeeName { get; set; }
    public String EmployeeName2 { get; set; }
    public String EmployeeName3 { get; set; }
    //Constructor
  public customcontroller4()
  {
    EmployeeName = ApexPages.currentPage().getParameters().get('EN');
    EmployeeName2 = ApexPages.currentPage().getParameters().get('EN2');
    EmployeeName3 = ApexPages.currentPage().getParameters().get('EN3');

  }
}


*Use 'assignedTo' in VF page instead of using 'ApexPages.CurrentPage().getParameters().get('name')'

http://srinusfdc.blogspot.in/2012/07/actionfunction-in-vf.html

http://www.forcetree.com/2009/06/passing-parameters-to-visualforce-page.html

http://visualsalesforce.blogspot.in/2011/03/passing-values-between-pages-in.html

Pick List in VF

Simple Pick List without using controller:
<apex:page >
<apex:form >
  <apex:selectList size="1">
      <apex:selectoption Itemlabel="India" Itemvalue="India"/>
      <apex:selectoption Itemlabel="India" Itemvalue="USA"/>
      <apex:selectoption Itemlabel="India" Itemvalue="UK"/>
  </apex:selectList>
</apex:form>
</apex:page>
*******************
Simple Pick List by using controller:

<apex:page controller="actionregionInterview">
<apex:form >
  <apex:selectList size="1">
      <apex:selectoptions value="{!items}"/>
  </apex:selectList>
</apex:form>
</apex:page>
-------------------------------
public class actionregionInterview {   
    public List<SelectOption> getItems() {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new selectoption('India', 'India'));
        options.add(new selectoption('Us', 'Us'));
        options.add(new selectoption('Australia', 'Australia'));
        return options;
    }

    /*String[] Countries = new String[] {};
    public String[] getCountries() {
       
        return countries;
    }
        public void setCountries(String[] countries) {
       
        this.countries = countries;
    }*/

}
*************************

Monday, 16 July 2012

To display all the fields of sObject using Apex & VF


<apex:page showHeader="false" Controller="FieldsClass">
        <apex:DataTable value="{!data}" var="d">
             <apex:column headerValue="Field Name">
                 {!d}
             </apex:column>          
         </apex:DataTable>
</apex:page>
*******************************
public class  FieldsClass {

     public map<string,Schema.SObjectField> data {get;set;}
   
     public  FieldsClass (){
         data = Schema.SObjectType.Book__c.fields.getMap();
        }
    }

Radio-buttons simple code



<apex:page controller="search">
<apex:form >
<apex:selectRadio value="{!searchCategory}" >
    <apex:selectOption itemValue="Member one" itemlabel="Member"/>
    <apex:selectOption itemValue="Blog" itemlabel="Blog"/>
    <apex:selectOption itemValue="Photo" itemlabel="Photo"/>
</apex:selectRadio>
</apex:form>
</apex:page>
*****************************
public class search {

    public String searchCategory { get; set; }

    // Constructor of the class
    public search()
    {
    searchCategory = 'Member one';
    } 
   
}


Labels