Capitalize First Name, LastName, and All Address Fields of Account

Featured

Trigger On Account Object

trigger ChangingFirstlttrUpper on Account (before insert,before update) {
   ChanignToCaps.Change(trigger.new);
      if(trigger.isBefore )
         if(trigger.IsInsert ||trigger.IsUpdate )
           ChanignToCaps.Change(trigger.new);
} 

Apex Class

global class ChanignToCaps{
   global static void Change( Account [] acc){
      for(Account a :acc){
         if(a.Name!=null || a.Name != ' '){
           a.name= formatToUpper(a.name);
   }
   if(a.BillingStreet != null )
    a.BillingStreet = formatToUpper(a.BillingStreet);

   if(a.BillingCity !=null)
    a.BillingCity = formatToUpper(a.BillingCity);

   if(a.BillingState !=null )
    a.BillingState= formatToUpper(a.BillingState);

   if(a.BillingPostalCode !=null )
    a.BillingPostalCode = formatToUpper(a.BillingPostalCode);

   if(a.BillingCountry !=null )
    a.BillingCountry= formatToUpper(a.BillingCountry);
   }
}

formatToUpper Is A Static Function Which Does The Acutal Work:

public static String formatToUpper (String Str) {
String result = '';
for (String iter : Str.split('[ ]+')) {
   if (iter != null && iter != '') {
    if (iter.length() > 1) {
     result += iter.substring(0,1).toUpperCase() + iter.substring(1,iter.length()) + ' ';
    }
    else
     result += iter.substring(0,1).toUpperCase() + ' ';
   }
}
return result;
}
}
Capitalize First Name, LastName, and All Address Fields of Account

Capitalize First Name, LastName, and All Address Fields of Account

Advertisements

Displaying Related Records In A Group Wise

Featured

<apex:page controller="groupwisedisplay" sidebar="false" title="Displaying Related Records In A Group Wise" showHeader="false">
 <!-- Begin Default Content REMOVE THIS -->
 <h1> Displaying Related Records In A Group Wise </h1>
 <br>===================================</br>
 <apex:repeat value="{!StartHere}" var="gp">
   <li>
 <strong>
 <apex:outputText style="color:blue;" value="{!gp.acc.Name}"/>
 </strong>
    <ul>
     <apex:repeat value="{!gp.con}" var="p">
      <li> (Contact) &nbsp;
       <apex:outputText style="color:green" value="{!p.FirstName}"/> &nbsp;
       <apex:outputText style="color:green;" value="{!p.LastName}"/>
    <ul >
     <li ><ol>
      (Case)<apex:repeat value="{!p.Cases}" var="child">
     <li >
      <apex:outputText style="color:gray;" value="{!child.Subject}"/>
     </li>
     </apex:repeat>
    </ol></li>
 </ul>
 </li>
 <br></br>
 </apex:repeat>
 </ul>
 <ul>
 <apex:repeat value="{!gp.opp}" var="p">
 <li> (Opportunity) &nbsp;
 <apex:outputText style="color:red" value="{!p.Name}"/>
 <ul>
 <apex:outputLabel value="Close Date:" for="out1"/>
 <apex:outputText value="{!p.CloseDate}" id="out1"/> <br>
 <apex:outputLabel value="Stage:" for="out2"/>
 <apex:outputText value="{!p.StageName}" id="out2"/></br>
 </ul>
 </li>
     <br></br>
     </apex:repeat>
    </ul>
   </li>
 </apex:repeat>
 </apex:page>

 

Apex Code/ Controller

public class groupwisedisplay {

public list<wrapgroupwise> singlegroup;
public List<wrapgroupwise> getStartHere(){
singlegroup= new List<wrapgroupwise>();
List<Account> tempacc=[select Id, Name from Account Limit 10];

for(Integer i=0; i<tempacc.size() ; i++){
list <contact> tempcon=[SELECT Id, FirstName, LastName,(SELECT Id, CaseNumber,Subject From Cases) From Contact Where AccountId =:tempacc[i].id Limit 10];
list <Opportunity> tempopp=[SELECT Id,Name,CloseDate,StageName From Opportunity Where AccountId =:tempacc[i].id Limit 10];
singlegroup.add( new wrapgroupwise(tempacc[i],tempcon,tempopp));

}
return singlegroup ;

}
 //wrapper class
 public class wrapgroupwise{
 public List<contact> con {get;set;}
 public Account acc {get;set;}
 public List<Opportunity> opp {get;set;}

 public wrapgroupwise( Account a , list<Contact> c,list<Opportunity> o){
 acc=a;
 con=c;
 opp=o;
 } //end of wrapper class
 }
}

group wise displaying records

Type 6:Usage of Multi select Dependent picklist in vf & Apex

Featured

Dependent MultiSelect PickList

<apex:page controller="dependentone" sidebar="false" showHeader="false">
  <apex:form >
     <b> Dependent MultiSelect PickList</b>
     <br/>
     Select The Picklist Value(s):
    <apex:selectList value="{!myVal}" size="2" multiselect="true" title="Select The Picklist Value(s)">
       <apex:selectOption itemvalue="1s" itemlabel="Ones"/>
       <apex:selectOption itemvalue="2s" itemlabel="Twos"/>
       <apex:selectOption itemvalue="3s" itemlabel="Threes"/>
       <apex:selectOption itemvalue="4s" itemlabel="Fours"/>
       <apex:selectOption itemvalue="5s" itemlabel="Fives"/>
       <apex:actionSupport event="onchange" reRender="one"/>
   </apex:selectList>
   <br/>
   <apex:outputpanel id="one"> 
     <b>The selected value(s) are: </b>
      <apex:selectList size="1" value="{!selectedDepval}" >
        <apex:selectOptions value="{!depval}"/>
      </apex:selectList>
   </apex:outputpanel>
 </apex:form>
</apex:page>

Apex Code/Controller:

public class dependentone {
public String selecteddepval { get; set; }
public String myVal { get; set; }
 public List<SelectOption> getdepval() {
 List<SelectOption> options = new List<SelectOption>();
 if(myval==null)
 return null;
 else
 {
  if(myVal.contains('1s')){
 options.add(new SelectOption('One','1'));
 options.add(new SelectOption('Two','2'));
 options.add(new SelectOption('Three','3'));
 options.add(new SelectOption('Four','4'));
 options.add(new SelectOption('Five','5'));
 }

 if(myVal.contains('2s')){
 options.add(new SelectOption('Ten','10'));
 options.add(new SelectOption('Twenty','20'));
 options.add(new SelectOption('Thirty','30'));
 options.add(new SelectOption('Fourty','40'));
 options.add(new SelectOption('Fifty','50'));
 }
if(myVal.contains('3s')){
 options.add(new SelectOption('One Hundreed','100'));
 options.add(new SelectOption('Two Hundreed','200'));
 options.add(new SelectOption('Three Hundreed','300'));
 options.add(new SelectOption('Four Hundreed','400'));
 options.add(new SelectOption('Five Hundreed','500'));
 }
 if(myVal.contains('4s')){
 options.add(new SelectOption('One Thousand','1000'));
 options.add(new SelectOption('Two Thousand','2000'));
 options.add(new SelectOption('Three Thousand','3000'));
 options.add(new SelectOption('Four Thousand','4000'));
 options.add(new SelectOption('Five Thousand','5000'));
 }
 if(myVal.contains('5s')){
 options.add(new SelectOption('Ten Thousand','1000'));
 options.add(new SelectOption('Twenty Thousand','2000'));
 options.add(new SelectOption('Thrty Thousand','3000'));
 options.add(new SelectOption('Fourty Thousand','400,00'));
 options.add(new SelectOption('Fivty Thousand','500,00'));
 }
 }
 return options;

 }
}
Type 6:Usage of Multi select Dependent picklist in vf & Apex

Type 6:Usage of Multi select Dependent picklist in vf & Apex

Iteration Order for Maps and Sets Is Now Predictable (Summer 15 Release Update)

Hi Guys,

  1. Until this Spring 15 release, Maps and Sets are Unordered Collections. So the returned order will be random.
  2. But beginning from Summer 15 release onwards, Maps and Set order is predictable. The order will be same that what you put from the beginning to end.
Example:
 Map<String, String> orderedMap = new Map<String, String>();
 orderedMap.put('Good', 'This is so good');
 orderedMap.put('Bad', 'This is so bad');
 System.debug(orderedMap);

If you run the above code snippet in Developer console you will get the returned order as below,

Until Spring 15 Release:

{Bad=This is so bad, Good=This is so good}

From Summer 15 Release:

{Good=This is so good, Bad=This is so bad}

This changes is not the API level, this is Schema level change. If anyone relying on the Map or Set order in your codes, change it as soon.

Different Ways Of Using Apex:Param Tag

Aside

What Is Parm Tag?
<apex:Param> :- apex:param tag is used to hold java Script values.
param means parameter. This tag is also used to Pass values from 
java Script to an Apex controller. 

The <apex:param> component can only be a child of the following components:

  • <apex:actionFunction>
  • <apex:actionSupport>
  • <apex:commandLink>
  • <apex:outputLink>
  • <apex:outputText>
  • <flow:interview>

Syntax:

 <apex:param name="ParamName" value"{!someValue}" assignTo="{!someproperty}"/> 

value : Required = T R U E

Ques)So, When To Use assingTo & value And How To Use It?
Ans:
If you use value u can set the value to the query string param name like

<apex:param name="ParamName" value"1234"/> 

& Now, You can access this value in the controller using

Integer res=apexpages.currentpage().getparameters.get('ParamName');

 

If you use assingTo attribute then this will asigen the value to a property in the controller.
In Visualforce Page:

 <apex:param name="ParamName" value"{!someValue}" assignTo="{!someproperty}"/> 

In The Controller:

public string someproperty {get;set;} 

Now The Value What is Present in Value shall be assign to someproperty

 

Example:


<apex:page controller="paramexample">
 <apex:form >
 <apex:pageblock >
<apex:pageblockTable title="Accounts" value="{!acclist}" var="a">
<apex:column headervalue="Account name">
<apex:commandlink reRender="out" action="{!Paramdemo}">
{!a.name}
<apex:param name="aid" value="{!a.name}" assignTo="{!accname}"/>
</apex:commandlink>
</apex:column>
<apex:column value="{!a.phone}"/>
<apex:column value="{!a.industry}"/>
</apex:pageblockTable>
</apex:pageblock>

<apex:outputpanel id="out">
accname = {!accname}
</apex:outputpanel>

 </apex:form>
</apex:page>
public class paramexample
{
public string accname{get;set;}
public list<account> acclist { get; set; }

public paramexample(){
acclist = new list<account>();
for(account a : [select id, name, phone, industry from account limit 20])
acclist.add(a);
}

public void Paramdemo() {}
}
}

 

param example

ssing  param example

Click This To Know  Passing Parameters Using Javascript & ActionFunction

 

Automatically shows the Choose file Option / Button when a checkbox is selected.

whenever I select/check the checkbox (checkbox value=true) then the ChooseFile (inputfile) should display/show automatically .

Vf code:

<apex:page controller="example23">


<apex:form >

 <apex:inputCheckbox value="{!option}" >
<apex:actionsupport event="onclick" action="{!change}" />
</apex:inputCheckbox>


<apex:actionRegion rendered="{!bool}">

<apex:inputFile value="AttachFile" />


</apex:actionRegion>
</apex:form>

</apex:page>

Apex Controller:

public class example23 {

 public Boolean bool { get; set; }
 public Boolean option { get; set; }
 public PageReference change() {
 if(option == true)
 bool = true; 
 else 
 bool = false; 
 return null;
 }

public example23(){
bool =false;
}
 
}

 

To hide  tag

Using Trigger Updating Lookup filed.

To Update the Lookup field, Using Trigger Before Insert, Before Update.

Here I’am assuming Opportunity as Child and Budget_Master__c as Parent Object.
The Criteria is The From_Date__c(Date filed) & To_Date__c(Date filed) From Budget_Master__c must be in the range of given Opportunity RecCreatedDate__c(Datetime field)

trigger UpdateLookup on Opportunity (Before Insert,Before update) {
if(trigger.isInsert || trigger.isUpdate){
set<Budget_Master__c> BudMaster = new Set<Budget_Master__c>([Select Id, Name, From_Date__c,To_Date__c From Budget_Master__c]);

for(Opportunity  Op : Trigger.new){
for(Budget_Master__c BM :BudMaster ){
system.debug('------BFR IF---- ');
system.debug('------RecCreatedDate : '+(Op.RecCreatedDate__c).date());
 system.debug('------From: ' +BM.From_Date__c);
 system.debug('------ToDt: '+BM.To_Date__c );
 
If(  (((Op.RecCreatedDate__c).date()) >= BM.From_Date__c) && ((Op.RecCreatedDate__c).date()) <=(BM.To_Date__c)) {
Op.Budget_Master__c=BM.Id;
system.debug('------InSide IF---- ');
}//If closed
}//Inner for CLOSED
}//outer for CLOSED
}//if(trigger.isInsert || trigger.isUpdate) CLOSED
}//Trigger closed

Indian(Vedic) & International Number Conversion – In Word Format

<apex:page controller="NumberSystem" sidebar="false">
 <apex:form >
  <h1> Indian(Vedic) &amp; International Number System - In Word Format </h1>
  <br/><br/><br/>

  <apex:outputLabel for="txt1" value="Enter Number:">
  <apex:inputText value="{!num}" id="txt1" size="17" />
  <br/><br/>

  <apex:selectRadio border="0" legendText="Pick The Conversion Format" value="{!selectedValue}" layout="pageDirection" >
     <apex:selectOption itemLabel="Indian(Vedic) Number System " itemvalue="Indian" />
     <apex:selectOption itemLabel="International Number System" itemvalue="International" />
  </apex:selectRadio>

  <apex:commandButton value="Convert" action="{!NumConvert}" reRender="outpan" status="actstatusId"/>

  <apex:actionStatus id="actstatusId" >
     <apex:facet name="start">
        <img src="/img/loading.gif"/>
     </apex:facet>
  </apex:actionStatus>

   &nbsp;   
  <apex:outputPanel id="outpan">
  <b> {!result} </b>
  </apex:outputPanel>

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

Apex Code/Controller:

public class NumberSystem {

 public String selectedvalue { get; set; }
 public transient string num { get; set; }
 public transient string result { get; set; }
 public transient string out{get;set;}
 integer i=0,j=1;
 integer flg=0,flg1=1;
 integer length,len;
//constructor
 public NumberSystemfinal1(){
 selectedvalue='Indian';
 }
 //command button
 public PageReference NumConvert() {
   if(!(boolean)num.isNumeric())
     result='Incompatible, Try Numeric Format Only';
   else{
      try{
          num = string.valueOf(long.valueOf(num));
      } catch(TypeException e){
          System.debug('****************************************');
          System.debug('The Following Exception Occurred:'+e.getMessage());
          System.debug('****************************************');
        }//catch closed
     len=num.length();
     out=' ';
     if(length > 15)
         result='Number Out Of Range, Max Of 15 Digits Only';
     else if(selectedvalue=='International')
         result=internationalConversion();
     else
        result=indianConversion();
   }//outer else closed
   return null;
 }//NumConvert (CommandButton)Closed

In Indian Conversion

public string indianConversion(){
   length=len; i=0;j=1;
 while(length >= 1)
 {
   if(length==15||length==13||length==11||length==9||length==7||length==5||length==2) {
     if(num.substring(i,j)=='0'){
        length--;flg1=flg=0;
        i++; j++;
     }
     else if(num.substring(i,j)=='1'){
         out+= twoDigitTeen();
         length--; flg1=flg=1;
         i++; j++;
     }//inner else if closed
     else{
          out+= twoDigitzero();
          length--; flg=0;flg1=1;
          i++; j++;
     }
   }//outer if closed
  if((length==14||length==12||length==10||length==8||length==6||length==4||length==3||length==1)&&(flg==0))
  {
    if(num.substring(i,j)=='0' && flg1==0)
       flg1=0;
    else{
         flg1=1;
         out+=singleDigits();
    }//else closed
  }//outer if closed
   if(length==14 && flg1==1)
    out+=' Neel ';
   else if(length==12 && flg1==1)
    out+=' Kharab ';
   else if(length==10 && flg1==1)
    out+=' Arab ';
   else if(length==8 && flg1==1)
    out+=' Crore ';
   else if(length==6 && flg1==1)
    out+=' Lakhs ';
   else if(length==4 && flg1==1)
    out+=' Thousand ';
   else if(length==3){
       if(num.substring(i,j)!='0')
           out+=' Hundreed ';
   }
   flg=0;length--;
   i++;j++;
 }//while closed
 return out;
}//indianConvertion Closed

In International Conversion

 public string internationalConversion(){
  out=''; flg1=1;
  length=len; i=0;j=1;
  while(length >= 1){
    if(length==15||length==12||length==9||length==6||length==3){
       if(num.substring(i,j)!='0'){
         out+=(singleDigits()+'Hundreed');
         flg1=0;
       } else
            out+=singleDigits();
      length--; i++;j++;
    }//if closed
    if(length==14||length==11||length==8||length==5||length==2){
       if(num.substring(i,j)=='0' && flg1==1){
          flg1=1;length--;
          i++; j++;
       }
       else if(num.substring(i,j)=='1'){
           out+= twoDigitTeen();
           length--; flg=1; flg1=0;
           i++; j++;
       }//inner else if closed
      else{
           out+= twoDigitzero();
           length--; flg=0;flg1=0;
           i++; j++;
      }//else closed
    }//outer if closed 

   If((length/3==1||length==1)&& (flg==0)){
       if((num.substring(i,j)=='0') && (flg1==1))
          flg1=1;
       else{
            flg1=0;
            out+=singleDigits();
       }//outer else closed
   }//outer if closed
   if(length==13 && flg1==0)
       out+=' Trillion ';
   else if(length==10 && flg1==0)
       out+=' Billion ';
   else if(length==7 && flg1==0)
       out+=' Million ';
   else if(length==4 && flg1==0)
       out+=' Thousand ';
    flg=0;length--;
    i++;j++;flg1=1;
  } //while closed
  return out;
}//internationalConvertion closed

//Code for Calculating Two Digit Non Zero Numbers

public String twoDigitTeen(){
 transient string temp;
 if(num.substring(i+1,j+1)=='1')
    temp = ' Eleven ';
 else if(num.substring(i+1,j+1)=='2')
    temp =' Twelve ';
 else if(num.substring(i+1,j+1)=='3')
    temp = ' Thirteen ';
 else if(num.substring(i+1,j+1)=='4')
    temp = ' Fourteen ';
 else if(num.substring(i+1,j+1)=='5')
    temp =' Fifteen ';
 else if(num.substring(i+1,j+1)=='6')
    temp =' Sixteen ';
 else if(num.substring(i+1,j+1)=='7')
    temp =' Seventeen ';
 else if(num.substring(i+1,j+1)=='8')
    temp =' Eighteen ';
 else if(num.substring(i+1,j+1)=='9')
    temp =' Ninteen ';
 else if(num.substring(i+1,j+1)=='0')
    temp =' Ten ';
 else temp='';
 return temp;
}//twoDigitTeen ends

//Code for Calculating Two Digit  Zero Numbers

public string twoDigitzero(){
 transient string temp;
 if(num.substring(i,j)=='2')
    temp =' Twenty ';
 else if(num.substring(i,j)=='3')
    temp =' Thirty ';
 else if(num.substring(i,j)=='4')
    temp =' Fourty ';
 else if(num.substring(i,j)=='5')
    temp =' Fifty ';
 else if(num.substring(i,j)=='6')
    temp =' Sixty ';
 else if(num.substring(i,j)=='7')
    temp =' Seventy ';
 else if(num.substring(i,j)=='8')
    temp =' Eighty ';
 else if(num.substring(i,j)=='9')
    temp =' Ninty ';
 else temp='';
return temp;
}//twoDigitzero ends

//Code for Calculating Single Digit  Numbers

public string singleDigits(){
 transient string temp;
 if(num.substring(i,j)=='1')
   temp =' One ';
 else if(num.substring(i,j)=='2')
   temp =' Two ';
 else if(num.substring(i,j)=='3')
   temp =' Three ';
 else if(num.substring(i,j)=='4')
   temp =' Four ';
 else if(num.substring(i,j)=='5')
   temp =' Five ';
 else if(num.substring(i,j)=='6')
   temp =' Six ';
 else if(num.substring(i,j)=='7')
   temp =' Seven ';
 else if(num.substring(i,j)=='8')
   temp =' Eight ';
 else if(num.substring(i,j)=='9')
   temp =' Nine ';
 else temp= '';
return temp;
}//singleDigits ends
}//controller closed

NUMBER To Word Conversion

Type 5:Usage of Dynamic picklist in vf & Apex


<apex:page controller="dynamicpickone" sidebar="false" showHeader="false">

<apex:form >
 <apex:selectList id="selectpick" size="1" value="{!selectedValue}">
 <apex:selectOptions value="{!pickOptions}"/>
 <apex:actionSupport event="onchange" reRender="one"/>
 </apex:selectList>

<apex:outputPanel id="one">Selected Value is:
 <apex:outputText value="{!selectedValue}" />
 </apex:outputPanel>
 </apex:form>
 </apex:page>

Controller:

public class dynamicpickone{
//Constructor
public dynamicpickone() {

Parent = new Parent__c();
pickOptions = new List<SelectOption>();

// Use DescribeFieldResult object to retrieve commodities field.
// statusFieldDescription=sFD
Schema.DescribeFieldResult sFD = Parent__c.commodities__c.getDescribe();

// For each picklist value, create a new select option
//picklistEntry=plE
for (Schema.Picklistentry plE:sFD.getPicklistValues()){

pickOptions.add(new SelectOption(plE.getValue(),plE.getLabel()));

// obtain and assign default value
//if (picklistEntry.defaultValue){
// Parent.commodities__c = pickListEntry.getValue();
// }
}
}

Type 5:Usage of Dynamic picklist in vf & Apex

Type 5:Usage of Dynamic picklist in vf & Apex

Type 4:Usage of picklist in vf & Apex

Some times we need to display picklist in Vf page which is of type picklist in Sobject. Acutally we are not displaying the picklist values but then picklist record values which may have redundency…lets take an example .


<apex:page controller="picklistexamp2" showHeader="false" sidebar="false">

 <apex:form >
  <apex:selectList size="1" value="{!selectedValue}">
   <apex:selectOptions value="{!values}"/>
   <apex:actionSupport event="onchange" reRender="one"/>
  </apex:selectList><br/>
  <apex:outputLabel id="one"><b> The selected value is : {!selected     Value}<b></apex:outputlabel>
  </apex:form>
</apex:page>

Controller


public class picklistexamp2{
public List<selectoption> getValues() {
List< selectOption> ls= new list<selectOption>();
for(Parent__c p:[select commodities__c from Parent__c]){
ls.add(new selectOption(p.commodities__c,p.commodities__c));
}
return ls;
}
public String selectedValue { get; set; }
}

Out put: Here it is displaying the totla number of picklist values present in the records but not the picklist values present in it.

 one
To Resolve this we Use Map , By Using Map We can get all unique values in the map and we can store in list to display finally.
and the for this is


List< selectOption> ls= new list<selectOption>();

map <string,selectoption> map1= new map<string,selectoption>();

for(Parent__c p:[select commodities__c from Parent__c]){
map1.put(p.commodities__c, new selectoption(p.commodities__c,p.commodities__c));
}
ls=map1.values();
return ls;
}

one