Monday, 18 November 2013

Dependent Picklist

<apex:page controller="dpickcontroller">
   <apex:form >
      <apex:pageBlock title="Dependent Picklist">
        <apex:pageBlockSection columns="6">
         <apex:selectList size="1" value="{!country}">
         <b>Country</b> <apex:selectOptions value="{!con}" id="co"/>
         <apex:actionSupport event="onchange" reRender="st,ct"/>
         </apex:selectList>
         <apex:selectList value="{!state}" size="1" id="st">
          <b>State</b><apex:selectOptions value="{!sta}"/>
          <apex:actionSupport event="onchange" reRender="ct"/>
         </apex:selectList>
         <apex:selectList value="{!city}" size="1" id="ct">
          <b>City</b><apex:selectOptions value="{!cit}"/>
          <apex:actionSupport event="onchange" />
         </apex:selectList>
        </apex:pageBlockSection>
        <apex:pageBlockSection columns="6">
          <apex:selectList size="1" value="{!country2}">
         <b>Country2</b> <apex:selectOptions value="{!con2}" />
         <apex:actionSupport event="onchange" reRender="st2,ct2"/>
         </apex:selectList>
         <apex:selectList value="{!states}" size="1" id="st2">
          <b>State2</b><apex:selectOptions value="{!sta2}"/>
          <apex:actionSupport event="onchange" reRender="ct2"/>
         </apex:selectList>
         <apex:selectList value="{!cities}" size="1" id="ct2">
          <b>City2</b><apex:selectOptions value="{!cit2}"/>
         </apex:selectList>
        </apex:pageBlockSection>
      </apex:pageBlock>
    </apex:form>
</apex:page>

---------------

public with sharing class dpickcontroller {

    public List<SelectOption> getCon2() {
     List<SelectOption> options4 = new List<SelectOption>();
        options4.add(new SelectOption('none','none'));
        options4.add(new SelectOption('Indona','Indona'));
        return options4;
    }
 
    public List<SelectOption> getSta2() {
     List<SelectOption> options5 = new List<SelectOption>();
       options5.add(new SelectOption('none','none'));
       if(country2 == 'none'){
        states = 'none';
        cities = 'none';
       }
        else if(country2 == 'Indona'){
          options5.add(new SelectOption('AP1','AP1'));
          options5.add(new SelectOption('Jaipur1','Jaipur1'));
          options5.add(new SelectOption('Delhi1','Delhi1'));
        }
        return options5;
    }

    public List<SelectOption> getCit2() {
     List<SelectOption> options6 = new List<SelectOption>();
       options6.add(new SelectOption('none','none'));
        if(states == 'AP1'){
          options6.add(new SelectOption('Hyd1','Hyd1'));
          options6.add(new SelectOption('Mbnr1','Mbnr1'));
          options6.add(new SelectOption('kmm1','kmm1'));
        }
        return options6;
    }
       
    public String cities { get; set; }
    public String states { get; set; }
    public String country2 { get; set; }
    public String city { get; set; }
    public String state { get; set; }
    public String country { get; set; }

    public List<SelectOption> getCon() {
    List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('none','none'));
        options.add(new SelectOption('INDIA','INDIA'));
        options.add(new SelectOption('US','US'));
        options.add(new SelectOption('CANADA','Canada'));
       // options.add(new SelectOption('MEXICO','Mexico'));
       return options;
    }
 
    public List<SelectOption> getSta() {
     List<SelectOption> options2 = new List<SelectOption>();
       options2.add(new SelectOption('none','none'));
        if(country == 'none'){
         state = 'none';
         city = 'none';
        }
        else if(country == 'india'){
          options2.add(new SelectOption('AP','AP'));
          options2.add(new SelectOption('Jaipur','Jaipur'));
          options2.add(new SelectOption('Delhi','Delhi'));
        } else if(country == 'US'){
          options2.add(new SelectOption('New York','New York'));
          options2.add(new SelectOption('Boston','Boston'));
          options2.add(new SelectOption('Mexico','Mexico'));
        } else if(country == 'Canada'){
          options2.add(new SelectOption('Toronto zoo','Toronto zoo'));
          options2.add(new SelectOption('Niagara falls','Niagara falls'));
          options2.add(new SelectOption('CN Towers','CN Towers'));
        }
        return options2;
    }

    public List<SelectOption> getCit() {
      List<SelectOption> options3 = new List<SelectOption>();
       options3.add(new SelectOption('none','none'));
        if(state == 'AP'){
          options3.add(new SelectOption('Hyd','Hyd'));
          options3.add(new SelectOption('Mbnr','Mbnr'));
          options3.add(new SelectOption('kmm','kmm'));
          options3.add(new SelectOption('sec','sec'));
        } else if(state == 'New York'){
          options3.add(new SelectOption('‎Central Park','Central Park'));
          options3.add(new SelectOption('West Village Stroll','West Village Stroll'));
          options3.add(new SelectOption('Grimaldi Pizzeria','Grimaldi Pizzeria'));
        } else if(state == 'Boston'){
          options3.add(new SelectOption('Fenway Park','Fenway Park'));
          options3.add(new SelectOption('Faneuil hall','Faneuil hall'));
          options3.add(new SelectOption('Castle Island','Castle Island'));
          }
        return options3;
    }
}

Friday, 15 November 2013

Number to word converter

Visualforce code :



<apex:page controller="Numbertowordclass">
  <apex:form >
  <apex:pageBlock id="pb" >
  <apex:panelGrid columns="2">
   Enter Number:<apex:inputText value="{!num}" size="60"/>
   Enter word:<apex:inputText value="{!wrd}" size="60"/> 
  </apex:panelGrid>
  <apex:pageBlockButtons >
  <apex:commandButton value="Convert" action="{!convert}" reRender="pb"/>
  <apex:commandButton value="Cancel" action="{!Cancel}" reRender="pb"/>
  </apex:pageBlockButtons>
  </apex:pageBlock>
  </apex:form>
</apex:page>


Apex  code :


//This Class will support upto 12 digits :-

public with sharing class Numbertowordclass {

    public void Refresh(){
    num= null;
    wrd= null;
    }

    public PageReference Cancel() {
        Refresh();
        return null;
    }


    public string wrd{set;get;}
    public long num { get; set; }
  
    public string convert() {
      wrd=convert(num);
      return null;
    }
    public String[] units = new String[]{'Zero ','One ','Two ','Three ','Four ','Five ','Six ','Seven ','Eight ','Nine
        ','Ten ', 'Eleven ','Twelve ','Thirteen ','Fourteen ','Fifteen ', 'Sixteen ','Seventeen ','Eighteen ',
        'Nineteen '};
    public String[] tens = new String[]{'','','Twenty','Thirty','Forty','Fifty','Sixty','Seventy','Eighty','Ninety'};
 
    //This method is used to convert the integer to words
    public  String convert(long i) {
      //
      if( i < 20)  return units[integer.valueOf(i)];
      if( i < 100) return tens[integer.valueOf(i)/10] + ((math.mod(i , 10) > 0)? '' + convert(math.mod(i , 
         10)):'');
      if( i < 1000) return units[integer.valueOf(i)/100] + ' Hundred ' + ((math.mod(i , 100) > 0)?' ' + 
        convert(math.mod(i , 100)):'');
      if( i < 10000) return units[integer.valueOf(i)/1000] + ' Thousand ' + ((math.mod(i , 1000) > 0)?' ' + 
        convert(math.mod(i , 1000)):'');
      if( i < 1000000) return convert(i / 1000) + ' Thousand ' + ((math.mod(i , 1000) > 0)? '' +  
         convert(math.mod(i ,1000)):'') ;
      if(i < 100000000) return convert(i / 1000000) + ' Milion ' + ((math.mod(i , 1000000) > 0)? '' + 
        convert(math.mod(i , 1000000)):'') ;
      if(i < 1000000000) return convert(i / 1000000) + 'Milion ' + ((math.mod(i , 1000000) > 0)? '' + 
        convert(math.mod(i , 1000000)):'') ;    
      return convert(i / 1000000000) + ' Bilian ' + ((math.mod(i , 1000000000) > 0)? '' + 
        convert(math.mod(i , 1000000000)):'') ;
}
}
 


Wednesday, 13 November 2013

How to get Record Owner ID from record ID?

If u want to get the owner id/ user id of current record.

for this what I know, we have to do 2 things. 
1) First we have to fetch record ID from URL by using
   ApexPages.CurrentPage().getparameters().get('id');
2) We can fetch owner ID by using this record ID.
If I am correct then how to fetch record owner ID by using record ID? then leave a comment.

Tuesday, 5 November 2013

Difference between rendered, renderAs and reRender in Visualforce page



render - Boolean value (if it is true, it displays the block else it will be hidden)

reRender - ID. Particular block will be refreshed.

renderAs - Display the page as pdf, excel, etc...