Sunday, April 21, 2013

Creating Multiselect Picklist on Visualforce Page

Visualforce Page:


<apex:page controller="multiselectcls">
<apex:form >
<apex:panelGrid columns="3" id="abcd">

<apex:selectList id="sel1" value="{!leftselected}" multiselect="true" style="width:100px" size="5">
<apex:selectOptions value="{!unselectedvalues}" />
</apex:selectList>

<apex:panelGroup >
<br/>
<apex:CommandButton value="  >  " action="{!selectclick}"/> <br/>
<apex:CommandButton value="  <  " action="{!unselectclick}"/>
</apex:panelGroup>

<apex:selectList id="sel2" value="{!rightselected}" multiselect="true" style="width:100px" size="5">
<apex:selectOptions value="{!SelectedValues}" />
</apex:selectList>

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

Apex Class:


public with sharing class multiselectcls
{
     Set<String> originalvalues = new Set<String>{'A','B','C','D','E','F','G'};    
     Public List<string> leftselected{get;set;}    
     Public List<string> rightselected{get;set;}    
     Set<string> leftvalues = new Set<string>();    
     Set<string> rightvalues = new Set<string>(); 
             
     public multiselectcls()
     {        
     leftselected = new List<String>();        
     rightselected = new List<String>();        
     leftvalues.addAll(originalValues);    
     }         
     public PageReference selectclick()
     {        
     rightselected.clear();        
     for(String s : leftselected)
     {            
     leftvalues.remove(s);            
     rightvalues.add(s);        
     }        
     return null;    
     }        
      public PageReference unselectclick()
      {        
      leftselected.clear();        
      for(String s : rightselected)
      {            
      rightvalues.remove(s);            
      leftvalues.add(s);        
      }        
      return null;    
      }     
      public List<SelectOption> getunSelectedValues()
      {        
      List<SelectOption> options = new List<SelectOption>();        
      List<string> tempList = new List<String>();        
      tempList.addAll(leftvalues);        
      tempList.sort();        
      for(string s : tempList)            
      options.add(new SelectOption(s,s));        
      return options;    
      }     
      public List<SelectOption> getSelectedValues()
      {        
      List<SelectOption> options1 = new List<SelectOption>();        
      List<string> tempList = new List<String>();        
      tempList.addAll(rightvalues);        
      tempList.sort();        
      for(String s : tempList)            
      options1.add(new SelectOption(s,s));        
      return options1;    
      }
}

Saturday, April 20, 2013

Displaying Dependent Picklist Fields on a Visualforce Page without using Sobject

Visualforce Page:



<apex:page controller="dependentpicklist">  
    <apex:form >
        <apex:pageBlock >
            <apex:actionFunction name="State" action="{!StateToCity}"/>
            <apex:selectList multiselect="false" value="{!selectedState}" size="1" onchange="State()"> 
                <apex:selectOption itemLabel="-----None----" itemValue=""/>
                <apex:selectOptions value="{!listStates}"/>
            </apex:selectList>
            <apex:actionFunction name="City" action="{!CityToArea}"/>
            <apex:selectList multiselect="false" value="{!selectedCity}" size="1" onchange="City()" disabled="{!cityDisable}">            
                <apex:selectOption itemLabel="-----None----" itemValue=""/>
                <apex:selectOptions value="{!listCities}"/>
            </apex:selectList>            
            <apex:selectList multiselect="false" value="{!selectedArea}" size="1" disabled="{!areaDisable}">            
                <apex:selectOption itemLabel="-----None----" itemValue=""/>
                <apex:selectOptions value="{!listAreas}"/>
            </apex:selectList>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Apex Class:

public with sharing class dependentpicklist {

public Boolean areaDisable { get; set; }

public Boolean cityDisable { get; set; }

public dependentpicklist()
{
cityDisable=true;
areaDisable=true;
listStates = new List<SelectOption>();
listStates.add(new SelectOption('ANDHRA PRADESH','Andhra Pradesh'));
listStates.add(new SelectOption('TAMIL NADU','Tamil Nadu'));
listStates.add(new SelectOption('KARNATAKA','Karnataka'));
}
public PageReference StateToCity()
{
cityDisable=false;
if(selectedState=='ANDHRA PRADESH')
{
listCities = new List<SelectOption>();
listCities.add(new SelectOption('HYDERABAD','Hyderabad'));
listCities.add(new SelectOption('VIJAYAWADA','Vijayawada'));
listCities.add(new SelectOption('NELLORE','Nellore'));
}

if(selectedState=='TAMIL NADU')
{
listCities = new List<SelectOption>();
listCities.add(new SelectOption('CHENNAI','Chennai'));
listCities.add(new SelectOption('COIMBATORE','Coimbatore'));
listCities.add(new SelectOption('VELLORE','Vellore'));
}

if(selectedState=='KARNATAKA')
{
listCities = new List<SelectOption>();
listCities.add(new SelectOption('MYSORE','Mysore'));
listCities.add(new SelectOption('MANGALORE','Mangalore'));
listCities.add(new SelectOption('BANGALORE','Bangalore'));
}

return null;
}


public PageReference CityToArea()
{
areaDisable=false;
if(selectedCity=='HYDERABAD')
{
listAreas = new List<SelectOption>();
listAreas.add(new SelectOption('BANJARA HILLS','Banjara Hills'));
listAreas.add(new SelectOption('HITECH CITY','Hitech City'));
listAreas.add(new SelectOption('JUBILEE HILS','Jubilee Hills'));
}

if(selectedCity=='VIJAYAWADA')
{
listAreas = new List<SelectOption>();
listAreas.add(new SelectOption('KONDAPALLI FORT','Kondapalli Fort'));
listAreas.add(new SelectOption('GANDHI HILL','Gandhi Hill'));
listAreas.add(new SelectOption('KOLLERU LAKE','Kolleru Lake'));
}
if(selectedCity=='NELLORE')
{
listAreas = new List<SelectOption>();
listAreas.add(new SelectOption('A C NAGAR','A C Nagar'));
listAreas.add(new SelectOption('DARGA MITTA','Darga Mitta'));
listAreas.add(new SelectOption('GUDUR','Gudur'));
}
if(selectedCity=='CHENNAI')
{
listAreas = new List<SelectOption>();
listAreas.add(new SelectOption('ENNORE','Ennore'));
listAreas.add(new SelectOption('PERAMBUR','Perambur'));
listAreas.add(new SelectOption('ANNA NAGAR','Anna Nagar'));
}
if(selectedCity=='COIMBATORE')
{
listAreas = new List<SelectOption>();
listAreas.add(new SelectOption('RAM NAGAR','Ram Nagar'));
listAreas.add(new SelectOption('PERUR','Perur'));
listAreas.add(new SelectOption('R S PURAM','R S Puram'));
}
if(selectedCity=='VELLORE')
{
listAreas = new List<SelectOption>();
listAreas.add(new SelectOption('ALLA PURAM','Alla Puram'));
listAreas.add(new SelectOption('BAGAYAM','Bagayam'));
listAreas.add(new SelectOption('SAIDAPET','Saidapet'));
}
if(selectedCity=='MYSORE')
{
listAreas = new List<SelectOption>();
listAreas.add(new SelectOption('HINKAL','Hinkal'));
listAreas.add(new SelectOption('INDIRA NAGAR','Indira Nagar'));
listAreas.add(new SelectOption('BELVADI','Belvadi'));
}
if(selectedCity=='MANGALORE')
{
listAreas = new List<SelectOption>();
listAreas.add(new SelectOption('PEJAVARA','Pejavara'));
listAreas.add(new SelectOption('KENJAR','Kenjar'));
listAreas.add(new SelectOption('KOLAVOOR','Kolavoor'));
}
if(selectedCity=='BANGALORE')
{
listAreas = new List<SelectOption>();
listAreas.add(new SelectOption('BELLANDUR','Bellandur'));
listAreas.add(new SelectOption('AGARA','Agara'));
listAreas.add(new SelectOption('BANASANKARI','Banasankari'));
}

return null;
}


public List<SelectOption> listAreas { get; set; }

public String selectedArea { get; set; }

public List<SelectOption> listCities { get; set; }

public String selectedCity { get; set; }

public List<SelectOption> listStates { get; set; }

public String selectedState { get; set; }
}


Displaying Dependent Picklist Fields on a Visualforce Page using Custom Object

Dependent picklists in Salesforce are very useful. They are used to limit the list of values in one picklist based on the value of another picklist. An example would be if you had a list of countries, states/provinces and major cities. If you select a country you would want the list of states/provinces to be filtered in the next picklist. The state/province selected should then limit the major cities that would be available for selection.

Displaying dependent picklists is very simple with a Visualforce pageblockTable. Let’s assume that we have a custom object called locations with three custom fields called country__c, state__c and city__c. When the custom object is viewed the ‘Controlling Field’ column for state will be country and for city it will be state. If you go into the custom field for country or state you will see a ‘Field Dependencies’ section that will show the custom field that is being controlled by the values in this picklist. If the ‘edit’ link is clicked the dependent values can be managed by selecting values and click on the ‘Include Values’ or ‘Exclude Values’ buttons. Now that our dependent picklists are setup we can create our table by simply referencing those fields in the pageblockTable tag.


Apex Class:


public with sharing class locationController{
public list<location__c> locationList{get;set;}
public locationController(){
locationList = [Select ID, Country__c, State__c, City__c
From Location__c];
}
}

Visualforce Page:

<apex:page Controller="locationController"> Location Table <apex:messages style="color: red;">
</apex:messages> 
<apex:form> 
<apex:pageblock
<apex:pageblocktable var="locItem" value="{!locationList}">
<apex:column headerValue="Country">
<apex:inputfield value="{!locItem.Country__c}">
</apex:inputfield>
</apex:column> 
<apex:column headerValue="State/Province">
<apex:inputfield value="{!locItem.State__c}">
</apex:inputfield> 
</apex:column> 
<apex:column headerValue="City"> 
<apex:inputfield value="{!locItem.City__c}">
</apex:inputfield> 
</apex:column> 
</apex:pageblocktable> 
</apex:pageblock>
</apex:form> 
</apex:page>

Now what if there is a requirement that the country field should not be displayed? But the requirement is still that the state picklist should only display the correct values for that country. With some trial and error I found out that the country picklist has to be on the page. I tried to set the render property of the column to be false, but that did not work. I also tried to set the width of the column to be 1%, but it seemed like a minimum length was going to be given to display the field no matter how I set the length. Finally I ran across some css that would do the trick. Set the style value for the column to be this: style=“display:none;visibility:hidden”. Then the column is really there, but just not visible to the end user. The full column in Visualforce would look like this:






<apex:column style="display: none; visibility: hidden;" headerValue="Country">
<apex:inputfield value="{!locItem.Country__c}">
</apex:inputfield>
</apex:column>

Dependent picklist fields are very powerful and integrate so easily with Visualforce, but sometimes we need a little css help for a few final requirements.

/*
<apex:pageBlockSectionItem >
<apex:outputLabel value="Regions" style="position:relative;left:-100px"/>
<apex:inputField value="{!LeadInfo.Region__c}"/>
</apex:pageBlockSectionItem>

<apex:pageBlockSectionItem >
<apex:outputLabel value="City" style="position:relative;left:-60px"/>
<apex:inputField value="{!LeadInfo.City__c}"/>
</apex:pageBlockSectionItem>

*/

Sunday, April 7, 2013

If Checkbox is true then sending mail to user's mail id


Visualforce Page:

<apex:page controller="sendemailcls">
    <apex:form >
        <apex:pageBlock >
            <apex:actionFunction name="chang" action="{!sendmail}"/>
            <apex:inputCheckbox value="{!checkingbox}" onchange="chang()"/>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Apex Class:


public with sharing class sendemailcls {
    String Email;
    public PageReference sendmail() {
        if(checkingbox==true){
           
            Messaging.SingleEmailMessage msem= new Messaging.SingleEmailMessage();
            msem.setToAddresses(new string[] {Email});
            msem.setSubject('your input checkbox was checked');
            msem.setHTMLBody('<H1>This mail from salesforce</H1>');
            System.debug('------------------------------'+msem);
            Messaging.sendEmail(new Messaging.SingleEmailMessage[] {msem});
                              }
        return null;
    }


    public boolean checkingbox { get; set; }
    public sendemailcls(){
       String Userid= UserInfo.getUserid();
       User u=[select id,email from User where id=:Userid];
       Email=u.email;
                         }
}

Inserting multiple records at a time


Visualforce Page:

<apex:page StandardController="Account" extensions="MultiAdd" id="thePage">
<apex:form >
<apex:pageblock id="pb" >
    <apex:pageBlockButtons >        
        <apex:commandbutton value="Save" action="{!Save}"/>
    </apex:pageBlockButtons>
              <apex:pageblock id="pb1">
                    <apex:repeat value="{!lstInner}" var="e1" id="therepeat">
                <apex:panelGrid columns="7">                                                                                                              
                <apex:panelGrid >
                    <apex:facet name="header">Name</apex:facet>
                    <apex:inputfield value="{!e1.acct.Name}" required="false"/>
                </apex:panelGrid>
                <apex:panelGrid title="SPD" >
                    <apex:facet name="header">Phone</apex:facet>
                    <apex:inputfield value="{!e1.acct.Phone}"/>
                </apex:panelGrid>
                <apex:panelGrid title="SPD" >
                    <apex:facet name="header">Parent Account</apex:facet>
                    <apex:inputfield value="{!Account.ParentId}"/>
                </apex:panelGrid>
                <apex:panelGrid headerClass="Name">
                    <apex:facet name="header">Del</apex:facet>
                    <apex:commandButton value="X" action="{!Del}" rerender="pb1">
                        <apex:param name="rowToBeDeleted" value="{!e1.recCount}" assignTo="{!selectedRowIndex}"></apex:param>
                    </apex:commandButton>
                </apex:panelGrid>
                <apex:panelGrid headerClass="Name">
                    <apex:facet name="header">Add</apex:facet>
                    <apex:commandButton value="+" action="{!Add}" rerender="pb1"/>                        
                </apex:panelGrid> 
            </apex:panelgrid>                                        
        </apex:repeat>
    </apex:pageBlock>        
</apex:pageblock>
</apex:form>
</apex:page>

Apex Class:

public with sharing class MultiAdd {
    
//will hold the account records to be saved
    public List<Account>lstAcct  = new List<Account>();
    
    //list of the inner class
    public List<innerClass> lstInner 
    {   get;set;    }
    
    //will indicate the row to be deleted
    public String selectedRowIndex
    {get;set;}  
    
    //no. of rows added/records in the inner class list
    public Integer count = 1;
    //{get;set;}
    
    
    ////save the records by adding the elements in the inner class list to lstAcct,return to the same page
    public PageReference Save()
    {
        PageReference pr = new PageReference('/apex/insertaccs');
        
        for(Integer j = 0;j<lstInner.size();j++)
        {
            lstAcct.add(lstInner[j].acct);
        } 
        insert lstAcct;
        pr.setRedirect(True);
        return pr;
    }
        
    //add one more row
    public void Add()
    {   
        count = count+1;
        addMore();      
    }
    
    /*Begin addMore*/
    public void addMore()
    {
        //call to the iner class constructor
        innerClass objInnerClass = new innerClass(count);
        
        //add the record to the inner class list
        lstInner.add(objInnerClass);    
        system.debug('lstInner---->'+lstInner);            
    }/* end addMore*/
    
    /* begin delete */
    public void Del()
    {
        system.debug('selected row index---->'+selectedRowIndex);
        lstInner.remove(Integer.valueOf(selectedRowIndex)-1);
        count = count - 1;
        
    }/*End del*/
     
    /*Constructor*/
    public MultiAdd(ApexPages.StandardController ctlr)
    {
    
        lstInner = new List<innerClass>();
        addMore();
        selectedRowIndex = '0';
        
    }/*End Constructor*/
        
    /*Inner Class*/
    public class innerClass
    {       
        /*recCount acts as a index for a row. This will be helpful to identify the row to be deleted */
        public String recCount
        {get;set;}
        
        
        public Account acct 
        {get;set;}
        
        /*Inner Class Constructor*/
        public innerClass(Integer intCount)
        {
            recCount = String.valueOf(intCount);        
            
            /*create a new account*/
            acct = new Account();
            
        }/*End Inner class Constructor*/    
    }/*End inner Class*/
}

Creating Login page


Visualforce Page:

<apex:page controller="wavuhlogincls" showHeader="false">
<style>
.labelcls{color:white;font-weight:bold;font-size:30px;}
</style>
    <apex:form >
   <head>
    <div style="background-color:#125AA4" id="div">
    <table style="height:20px">
    <tr>
        <td >
            <apex:outputLabel value="WavuH" style="color:white;font-weight:bold;font-family: Forte;font-size:30px;margin-left:250px;"></apex:outputLabel>
        </td>
    </tr>
    </table>
    </div></head>
        <apex:pageblock rendered="{!logintable}">
    <body>
        <table width="100%" border="0" height="100%" >
            <tr>
            <td width="65%" style="padding-bottom:300px;">
                    <div > <apex:outputLabel style="color:#810988; margin-left:250px; font-size:20px ">
                            <h1>ERP made simple, affordable</h1>
                            </apex:outputLabel>
                    </div><br/>
                    <table border="0">
                        <tr>
                        <td>
                            <apex:image value="{!$Resource.crm}" style="margin-left:250px"/ >
                        <td style="padding-bottom:14px"> 
                                <apex:outputLabel value="CRM" style="font-weight:bold; margin-left:20px"/><br/>
                                <apex:outputLabel value="understand and manage your customers at a glance" style="margin-right:50px; margin-left:20px"/>
                        </td>
                       </td>     
                       </tr> 
                    </table>
                     <table border="0">
                        <tr>
                        <td>
                            <apex:image value="{!$Resource.hr}" style="margin-left:250px"/ >
                        <td style="padding-bottom:14px"> 
                                <apex:outputLabel value="HR" style="font-weight:bold; margin-left:20px"/><br/>
                                <apex:outputLabel value="manage and pay your staffers efficiently through payroll & HRM" style="margin-right:50px; margin-left:20px"/>
                        </td>
                       </td>     
                       </tr> 
                    </table> 
                    
                   <table border="0">
                        <tr>
                        <td>
                            <apex:image value="{!$Resource.financials}" style="margin-left:250px"/ >
                        <td style="padding-bottom:14px"> 
                                <apex:outputLabel value="Financials" style="font-weight:bold; margin-left:20px"/><br/>
                                <apex:outputLabel value="comprehensive accounting and statistics for your business" style="margin-right:50px; margin-left:20px"/>
                        </td>
                       </td>     
                       </tr> 
                    </table>  
                    <table border="0">
                        <tr>
                        <td>
                            <apex:image value="{!$Resource.supplychain}" style="margin-left:250px"/ >
                        <td style="padding-bottom:14px"> 
                                <apex:outputLabel value="Supply Chain" style="font-weight:bold; margin-left:20px"/><br/>
                                <apex:outputLabel value="take control of your assets, inventory & procurement processes" style="margin-right:50px; margin-left:20px"/>
                        </td>
                       
                       </td>     
                       </tr> 
                    </table> <br/>
                        
                        <table>
                        <tr><td> <apex:outputlabel value="Don't hava a Wavuh Account?" style="margin-left:300px"/>&nbsp;&nbsp;
                       <apex:commandLink value="Get one here" style="color:blue" action="/apex/wavuhregistration"/></td></tr>
                       <tr><td style="padding-top:20px;">
                                <div align="center"><apex:commandlink value=" Login " action="{!loginpage}" style="color:blue;margin-left:300px"/>&nbsp;&nbsp;                              
                                <apex:commandlink value="Contact Us" action="{!contactus}" style="color:blue;"/></div></td></tr> 
                    </table>  
                    
                    </td>
                  
                     <td style="padding-top:70px">
                <table border="1" height="250px" width="60%" style="margin-bottom:350px; border-color:blue; border-width:0px; border-bottom-width:1px" rules="cols" >
                 <tr>
                     <td height="40px" bgcolor="#115499"><apex:outputLabel value="Login" style="color:white; font-weight:bold; font-size:20px"/></td> 
                 </tr>
                  <tr>
                  <td >
                  <div>
                 <apex:pagemessages ></apex:pagemessages>&nbsp;&nbsp;&nbsp;
                 <apex:outputLabel value="User Name" />
                 <apex:inputText style="margin-left:20px" value="{!uname}"/></div><br/>
                   <div>&nbsp;&nbsp;&nbsp;
                 <apex:outputLabel value="Password" />
                 <apex:inputText style="margin-left:25px" value="{!pwd}"/>
                    </div><br/>
                <div><apex:commandButton value="Sign in" style="margin-left:150px" action="{!permitlogin}"/></div><br/><br/>
                <div align="center"><apex:commandLink value="Forgot your Password?" style="color:red" action="{!forgotpwd}"/></div>
                </td>
                </tr>                                
               </table> 
            </td>
                    </tr>
          </table>
          </body>
          </apex:pageblock>
          
 <!--   <apex:pageblock rendered="{!logintable}">
    <table align="right" width="35%"><tr><td>
    <div style="background-color:#125AA4">
    <table style="height:10px">
    <tr>
        <td>
            <apex:outputLabel value="Login" styleClass="labelcls"></apex:outputLabel>
        </td>
        
    </tr>

</table>
</div><br/>
        <apex:pagemessages ></apex:pagemessages>
 <apex:outputLabel value="User Name or Password does not match" rendered="{!show}" style="color:red"/>
    <tr><td style="padding-top:20px"><div align="center">Username<apex:inputtext value="{!uname}"/></div></td></tr>
    <tr><td style="padding-top:20px"><div align="center">Password<apex:inputsecret value="{!pwd}"/></div></td></tr>
    <tr><td style="padding-top:20px"><div align="center"><apex:commandButton value="Signin" action="{!permitlogin}"/></div></td></tr>
    <tr><td style="padding-top:20px"><div align="center"><apex:commandLink value="Forgot your Password?" style="color:red" action="{!forgotpwd}"/></div></td></tr>
    </td></tr> </table><br/><br/>
        
    <apex:outputlabel >Don't hava a Wavuh Account?</apex:outputlabel>&nbsp;&nbsp;<apex:commandLink value="Get one here" style="color:blue" action="/apex/wavuhregistration"/>
    </apex:pageblock> -->
    
    <apex:pageblock rendered="{!resetpwd}">
    <br/>
    <div align="center">
    <apex:outputlabel style="font-size:13px;font-weight:bold">Kindly enter your email address below to send you a password</apex:outputlabel>
    </div>
     <br/>
     <table align="center"  border="1" height="20px" width="30%" style=" border-color:blue; border-width:0px; border-bottom-width:1px" rules="cols">
     <tr><td>   
        <table style="background-color:#125AA4" width="100%">
        <tr><td><apex:outputLabel value="Reset Password" style="color:white;font-weight:bold;font-size:20px;"></apex:outputLabel></td></tr>
        </table>
    </td></tr>
    <tr><td> 
    <table align="center" width="100%">  
    <tr><td> <apex:pagemessages ></apex:pagemessages></td></tr>      
    <tr><td style="padding-top:20px"><div align="center">Email<apex:inputtext value="{!mailid}" /></div></td></tr>
    <tr><td style="padding-top:20px"><div align="center"><apex:commandButton value="Send me Password" action="{!backtologin}"/></div></td></tr>
    <tr><td style="padding-top:20px; padding-bottom:20px">
    <div align="center"><apex:commandlink value=" Login " action="{!loginpage}" style="color:blue;"/>&nbsp;&nbsp;
    <apex:commandlink value="Contact Us" action="{!contactus}" style="color:blue;"/></div></td></tr>     
    </table></td></tr></table>
    </apex:pageblock>
    <apex:pageBlock rendered="{!contactdetails}">
        <table border="0" style="margin-left:250px">
                        <tr><td style="padding-bottom:40px;padding-top:25px"> 
                                <apex:outputLabel value="Contact Us" style="color:#E3170D;font-weight:bold;font-size:20px;"/>
                                </td></tr>
                                <tr><td>
                                <apex:outputLabel value="Main Office" style="font-size:15px;font-weight:bold;"/><br/><br/>
                                <apex:outputlabel value="5th Floor, Namdev Block"/><br/><br/>
                                <apex:outputlabel value="Prime Hospital Lane"/><br/><br/>
                                <apex:outputlabel value="S.r.Nagar"/><br/><br/>
                                <apex:outputlabel value="Phone:09440490498"/><br/><br/>
                                Email:  <a href=" mailto:gaddam.narayana86@gmail.com" style="color:blue;">gaddam.narayana86@gmail.com</a>
                                </td></tr> 
                                <tr><td style="padding-top:20px;">
                                <div align="center"><apex:commandlink value=" Login " action="{!loginpage}" style="color:blue"/>&nbsp;&nbsp;                              
                                <apex:commandlink value="Contact Us" action="{!contactus}" style="color:blue;"/></div></td></tr> 
         </table> 
    </apex:pageBlock>
    
    </apex:form>
</apex:page>

Apex Class:


public with sharing class wavuhlogincls {

    public boolean show { get; set; }
    public string uname{get; set;}
    public string pwd{get; set;}
    public List<Registration1__c> reg{get; set;}
    public PageReference permitlogin() {
        reg=[select id,Name,gnr__Password__c,Email__c from Registration1__c];
     for(Registration1__c r:reg){   
       if((uname==r.Name)&&(pwd==r.Password__c)){
            pagereference newpage=page.wavuhmenu;
            newpage.getparameters().put('my',uname);
            return newpage;
                                                }
       if((uname!=r.Name)||(pwd!=r.Password__c)){
       Apexpages.Message msg=new Apexpages.Message(Apexpages.severity.fatal,'User name or password does not match');
       Apexpages.addmessage(msg);
      // show=true;
                                                }    
                                }   
     return null;
                                      }    
    public string mailid{get; set;}
    string emailid;
    public Registration1__c reg1{get; set;}
    public PageReference backtologin() {                      
            reg=[select id,Name,gnr__Password__c,Email__c from Registration1__c]; 
            try{
            if(mailid!=''){                    
            if(mailid!=null)                
                reg1=[select id,Password__c,Email__c,name from Registration1__c where Email__c=:mailid];
                emailid=reg1.Email__c;
                Messaging.SingleEmailMessage msem= new Messaging.SingleEmailMessage();
                msem.setToAddresses(new string[] {emailid});
                msem.setSubject('Reset Password of your Wavuh Account');
                msem.setHTMLBody('Username:'+reg1.Name+'  and  password:'+reg1.Password__c);
                System.debug('------------------------------'+msem);            
                Messaging.sendEmail(new Messaging.SingleEmailMessage[] {msem});
                
                 Apexpages.Message msg=new Apexpages.Message(Apexpages.severity.info,'Password has been sent to '+mailid+' mail ID');
                 Apexpages.addmessage(msg);                            
                                  }                                                      
                                        
                           
                else{
                    Apexpages.Message msg=new Apexpages.Message(Apexpages.severity.fatal,'Enter  Email Address');
                    Apexpages.addmessage(msg);
                    }  
                } 
                catch(Exception e){
                      Apexpages.Message msg=new Apexpages.Message(Apexpages.severity.fatal,'Enter valid Email Address');
                      Apexpages.addmessage(msg);  
                                  }                                                             
        return null;
                                       }   
       
    public pagereference loginpage(){
            resetpwd=false;
            logintable=true;
            contactdetails=false;
            return null;
            
                                     }
     public boolean contactdetails{get; set;}                               
     public pagereference contactus(){
                 logintable=false;
                 resetpwd=false;
                 contactdetails=true;
                 return null;
                                     }
                                                                                                                                               
    public PageReference forgotpwd() {
        logintable=false;
        resetpwd=true;
        contactdetails=false;
            return null;
                                     }
    public wavuhlogincls(){
        logintable=true;
                          }
    public boolean logintable { get; set; }
    public boolean resetpwd { get; set; }
                                        
                                        }

Adding products to Opportunity product family


Visualforce Page:

<apex:page controller="myproductscls">
  <apex:form >
      <apex:pageBlock >
           <apex:actionFunction name="call" action="{!show}"/>
            <div align="center">
           Product Family:<apex:selectlist value="{!selectopt}" size="1" onchange="call()">
                <apex:selectOptions value="{!items}"/>
            </apex:selectlist> 
            </div>
          <apex:pageBlockTable value="{!lmw}" var="l">
              <apex:column headerValue="Select">
                  <apex:inputCheckbox value="{!l.selected}"/>
              </apex:column>
              <apex:column value="{!l.prodname}" headerValue="Name"/>
              <apex:column value="{!l.prodfamily}" headerValue="Family"/>
          </apex:pageBlockTable>
          <apex:pageBlockButtons >
              <apex:commandButton value="Add" action="{!addprod}"/>
          </apex:pageBlockButtons>
      </apex:pageBlock>
      
  </apex:form>
</apex:page>

Apex Class:


public with sharing class myproductscls 
{
    public PageReference addprod()
    {
        String oppid = Apexpages.currentpage().getparameters().get('opid');
        List<OpportunityLineItem> listopp=new List<OpportunityLineItem>(); 
        for(mywrapper w:lmw)
        {
            if(w.selected==true)
            {
                system.debug('-------------------------------------------------------------wrappers class boolean value is true');
                Opportunity oppor = [select pricebook2id from opportunity where id =:oppid ];
                
                List<pricebookentry> lpbe = [select id from pricebookentry where product2id = :w.prodid and pricebook2id =:oppor.pricebook2id];
                for(pricebookentry pbe : lpbe)
                {
                    opportunitylineitem ol = new opportunitylineitem();            
                    ol.pricebookentryid = pbe.id;
                    ol.Opportunityid = oppid;
                    ol.totalprice = 100.00;
                    ol.quantity = 10;
                    listopp.add(ol);
                }
            }
        }                         
        insert listopp;      
        return new Pagereference('/'+oppid);
    }

List<Product2> lp ;
public List<mywrapper> lmw {get; set;}
public List<selectoption> items {get; set;}
public String selectopt {get; set;}
public myproductscls(){
        items= new List<selectOption>();
        Schema.describefieldresult f= Schema.sobjecttype.Product2.fields.Family;
        System.debug('--------->'+f.getpicklistvalues());
        List<Schema.PicklistEntry> lst= f.getpicklistvalues();
        items.add(new selectoption('--','-None-'));
        for(Schema.PicklistEntry s: lst){        
            items.add(new selectOption(s.getvalue(), s.getlabel()));
                       }
lmw = new List<mywrapper>();
lp =[select name,family from product2];
if(lp.size()>0)
{
    for(product2 p : lp)
    {
        lmw.add(new mywrapper(p.name,p.family,p.id));
    }

}
}
public class mywrapper
{
    public String prodname{get; set;}
    public String prodid{get; set;}
    public String prodfamily{get; set;}
    public Boolean selected{get; set;}
    public mywrapper(String pname, String pfamily, String pid)
    {
        prodname = pname;
        prodid = pid;
        prodfamily = pfamily;
        selected = false;
    }
}
 public PageReference show(){
        lmw = new List<mywrapper>();
        lp=[select id,Name,Family from Product2 where Family=:selectopt];
        System.debug('---------------------------------------'+lp.size());
        if(lp.size()>0){
        for(Product2 pp:lp){           
            lmw.add(new mywrapper(pp.name,pp.family,pp.id));
                           }
                        }
        else{
            lmw=null;
            }
        
        return null;
                             }
}