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

Saturday, 4 August 2012

Display pageblocks based on the picklist selection

I got only partial Result, The challange is how to retrieve the selected values of picklist and compare them

VF

<apex:page controller="coun">
<apex:form >
<apex:selectlist label="Countries" size="1" value="{!country}">
<apex:actionSupport event="onchange" action="{!india}" rerender="India"/>
<apex:selectoption itemlabel="None" itemvalue="None"/>
<apex:selectoption itemlabel="India" itemvalue="India">
</apex:selectoption>
<apex:selectoption itemlabel="US" itemvalue="Us"/>
<apex:selectoption itemlabel="UK" itemvalue="Uk"/>
</apex:selectlist>
<apex:pageBlock >

<apex:outputPanel id="India">
<apex:pageBlockSection title="India" rendered="{!mhide}">
</apex:pageBlockSection>
</apex:outputPanel>

<apex:outputpanel id="Us">
<apex:pageBlockSection title="US" rendered="{!m1hide}">
</apex:pageBlockSection>
</apex:outputpanel>

<apex:outputpanel id="Uk">
<apex:pageBlockSection title="UK" rendered="{!m2hide}">
</apex:pageBlockSection>
</apex:outputpanel>

</apex:pageBlock>

</apex:form>
</apex:page>

APEX

public class coun {

    String country;
    public String getCountry() {
        return this.country;
    }
    public void setCountry(String counrty) {
        this.country = country;
    }
   
    public Boolean hide = false;
    public Boolean hide1 = false;
    public Boolean hide2 = false;
   
    public void setMhide(Boolean b) {
    this.hide = b;
    }
   
    public Boolean getMhide() {
    return this.hide;
    }
   
   
    public Boolean getM1hide() {
        return this.hide2;
    }
   
    public void setM1hide(Boolean b) {
      this.hide2 = b; 
    }
   
   
    public Boolean getM2hide() {
        return this.hide1;
    }
   
    public void setM2hide(Boolean b) {
        this.hide1 = b;
    }
   
   
    public PageReference india() {
       //if(country == 'India') {
        setMhide(true);
        setM2hide(false);
        setM1hide(false);
       // }      
        return null;
    }
   
     public PageReference us() {
        setM1hide(true);
        setM2hide(false);
        setMhide(false);
        return null;
    }
   
    public PageReference uk() {
        setM2hide(true);
        setM1hide(false);
        setMhide(false);
        return null;
    }  
   
}

Dispaly particular field based on the selection of the particular field

<apex:page standardController="Book__c">
<apex:form >
    <apex:pageBlock >
        <apex:pageBlockTable id="mytable" value="{!Book__c}" var="item">
  <apex:column headerValue="Delivery">
    <apex:actionRegion >       
      <apex:inputField value="{!item.City__c}">
        <apex:actionSupport event="onchange" reRender="mytable"/>
      </apex:inputField>
    </apex:actionRegion>
  </apex:column>
  <apex:column headerValue="Delivery Type">
    <apex:inputField rendered="{!item.City__c = 'Chennai'}" value="{!item.Chennai__c}"/>
    <apex:inputField value="{!item.Banglore__c}"/>
  </apex:column>
</apex:pageBlockTable>
    </apex:pageBlock>
</apex:form>
</apex:page>

We have three country buttons, if we click any button that country information should only display

VF
<apex:page controller="coun">
<apex:form >

<apex:commandButton value="India" action="{!india}" reRender="India,Us,Uk"/>
<apex:commandButton value="Us" action="{!us}" reRender="India,Us,Uk"/>
<apex:commandButton value="Uk" action="{!uk}" reRender="India,Us,Uk"/>

<apex:pageBlock >

<apex:outputPanel id="India">
<apex:pageBlockSection title="India" rendered="{!mhide}">
</apex:pageBlockSection>
</apex:outputPanel>

<apex:outputpanel id="Us">
<apex:pageBlockSection title="US" rendered="{!m1hide}">
</apex:pageBlockSection>
</apex:outputpanel>

<apex:outputpanel id="Uk">
<apex:pageBlockSection title="UK" rendered="{!m2hide}">
</apex:pageBlockSection>
</apex:outputpanel>

</apex:pageBlock>

</apex:form>
</apex:page>

APEX

public class coun {

    public Boolean hide = false;
    public Boolean hide1 = false;
    public Boolean hide2 = false;
   
    public void setMhide(Boolean b) {
    this.hide = b;
    }
   
    public Boolean getMhide() {
    return this.hide;
    }//Passing input dynamically through another method
   
   
    public Boolean getM1hide() {
        return this.hide2;
    }
   
    public void setM1hide(Boolean b) {
      this.hide2 = b; 
    }
   
   
    public Boolean getM2hide() {
        return this.hide1;
    }
   
    public void setM2hide(Boolean b) {
        this.hide1 = b;
    }
   
   
    public PageReference india() {
        setMhide(true);
        setM2hide(false);
        setM1hide(false);       
        return null;
    }
//displaying only india information and hiding other information
   
     public PageReference us() {
        setM1hide(true);
        setM2hide(false);
        setMhide(false);
        return null;
    }
   
    public PageReference uk() {
        setM2hide(true);
        setM1hide(false);
        setMhide(false);
        return null;
    }  
   
}

Explanation:
* For displaying or hiding we should use rendered, It contains either True or False.
* Instead of giving True or False, I would like to pass T/F dynmically using {!name}
* For {!name}, I would like to construct set and get method seperately.
* For set method, I would like to pass a boolean value through boolean datatype.
* For this I would like to pass the value through another method.
* Using, setmethodname(T/F) as a statement in another method.
* Through get method again I am returning the boolean value to rerenderd.
* By default, to put false I am taking a boolean type varibale.
* action, rerender, renderd should mainly use in VF page.

Friday, 3 August 2012

If you click on button a text msg should display on vf page

VF
<apex:page controller="temp">
<apex:form >
<apex:commandButton value="Click!" action="{!hai}"> 
<apex:actionSupport event="onclick" reRender="hi"/>
</apex:commandButton>
<apex:outputPanel id="hi">
{!msg}<!--By default it won't display, After clicking on button it will display-->
</apex:outputPanel>
</apex:form>
</apex:page>

APEX
public wih sharing class temp {

    public String msg { get; set; } //By default it has null value

    public PageReference hai() {
        msg = 'Hi'; //After clicking on this button it will display this value
        return null;
    }
}

Enhanced List in SFDC

Enhanced lists give you the ability to quickly view, customize, and edit list data to speed up your daily productivity.

Note: Listviews are aslo same as enhanced list but enhance list has more options like rowsperpage and height.

<apex:enhancedList type="Book__c" rowsPerPage="25" height="400"/>


  1.  'rowsPerPage' attribute must be one of the following values: [10, 25, 50, 100, 200].
  2. 'height' attribute is mandatory.
  3. 'type' attribute is mandatory 

Callout from APEX Triggers

Hide/show a pageBlock depending upon the button selection


VF:
' rendered' is used to hide or display visualforce elements
<apex:page controller="Wizard_3a_Controller">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection title="Rate Information">
Are there proposed non-standard electronic rates—<br/>
<apex:commandButton action="{!showSection1}" value="Yes" styleClass="btn" rerender="details"></apex:commandButton>
<apex:commandButton action="{!showSection2}" value="No" styleClass="btn"></apex:commandButton>
</apex:pageBlockSection>
<apex:outputPanel id="details">
<apex:pageBlockSection id="newData" title="Discount Rates" rendered="{!hideshow}">
Enter Proposal range
</apex:pageBlockSection>
</apex:outputPanel>
</apex:pageBlock>
</apex:form>
</apex:page>

APEX:
By default the page block is in hide mode due to datamember value i.e False
public class Wizard_3a_Controller
{

Boolean testval = false;
public pagereference showSection1() {
setHideshow(true);
return null; }

public pagereference ShowSection2()
{
setHideshow(false);
return null;
}

public Boolean getHideshow()
{
return this.testval;
}
public void setHideshow(boolean s)
{
this.testval = s;
}
}

Labels