Friday, January 17, 2014

Pagination

===========VFPage=============
<apex:page sidebar="false" standardController="Condidate__c" extensions="pagination2" >
  <apex:sectionHeader title="Pagintion" subtitle="Condidate"/>
    <apex:form id="fm">
       <apex:pageBlock id="pb" mode="inlineEdit">
          <apex:pageBlockSection id="ps" title="Condidate Records" columns="1" >
            <apex:pageBlockSectionItem >RecordsName</apex:pageBlockSectionItem>
                <apex:repeat value="{!mapCon[selectpage]}" var="A" >
                    <apex:outputlabel value="{!A.Name}"></apex:outputlabel>
               </apex:repeat>
               <apex:selectList value="{!Selectpage}" size="1">
                   <apex:selectOptions value="{!pageOption}"></apex:selectOptions>
               <apex:actionSupport event="onchange" action="{!NextPage}" />
             
             </apex:selectList>
          </apex:pageBlockSection>
       </apex:pageBlock>
    </apex:form>
</apex:page>
=============Controller==================
public with sharing class pagination2 {

    public Integer selectpage{set;get;}
   
    public Integer RecordsPerPage{set;get;}
   
    public Map<Integer,List<Condidate__c>> mapCon{set;get;}
   
    public List<selectOption> pageOption{set;get;}  

    public pagination2(ApexPages.StandardController controller) {
         
          mapCon=new map<Integer,List<condidate__c>>();
         
          RecordsPerPage=4;
         
          selectpage=1;
         
          List<Condidate__c> ConList=[select id, name from condidate__c];
             
              if(Conlist.size()>0){
                   Integer Total_Pages= conList.size()/ RecordsPerPage;
                   if(math.mod(conList.size(), RecordsPerPage)>0){
                        Total_Pages+=1;
                   }
                   pageOption=new list<selectoption>();
                 
                   Integer firstpage=0;
                 
                   Integer lastpage=RecordsPerPage;
                 
                   for(Integer i=0;i<Total_Pages;i++){
                 
                      Integer counter=i+1;
                     
                      pageoption.add(new selectoption(counter+'',counter+''));
                     
                      List<Condidate__c> listcon=new list<Condidate__c>();
                     
                      for(Integer j=firstpage;j<lastpage;j++){
                     
                         try{
                             listcon.add( conList[j]);
                         }
                         catch(Exception e){
                         }  
                      }
                     
                     firstpage=lastpage;
                     lastpage=RecordsPerPage*(i+2);
                     mapCon.put(counter,listcon);
                       
                   }
                 
              }
    }
  public void nextpage(){}
}

Reverse Number

============VFPage=================
<apex:page showHeader="false" controller="ReverseNNO" >
 <apex:form >
   <apex:pageBlock >
  <apex:pageBlockSection >
    EnterValue<apex:inputText value="{!num}"/>
     <center> <apex:commandButton value="Reverse" action="{!reverse}"/> </center>
     The Reverse Value<apex:inputText value="{!res1}" />
  </apex:pageBlockSection>
 </apex:pageBlock>
 </apex:form>
</apex:page>
=============Controller=======
public class ReverseNNO{

   // public PageReference reverse() {
     //   return null;
    //}

        public integer res1{set;get;}
        integer res=0;
        integer a=0;
        integer temp=0;
      public  integer num{set;get;}
    public void reverse(){
       a=num;
         while(a>0){
            temp=a/10;
            res=a-temp*10;
            res1=res1*10+res;
            res=0;
            a=temp;
       }
      //  system.debug(res1);
    }
   
}

Based On Picklist display Records

===========VFPage=================
<apex:page standardController="Opportunity" recordSetVar="opportunities"
tabStyle="Opportunity"
sidebar="false">
<apex:form >
<apex:pageBlock >
<apex:pageMessages />
<apex:pageBlock >
<apex:panelGrid columns="2">
<apex:outputLabel value="View:"/>
<apex:selectList value="{!filterId}" size="1">
<apex:actionSupport event="onchange" rerender="opp_table"/>
<apex:selectOptions value="{!listviewoptions}"/>
</apex:selectList>
</apex:panelGrid>
</apex:pageBlock>
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!save}"/>
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!opportunities}" var="opp" id="opp_table">
<apex:column value="{!opp.name}"/>
<apex:column headerValue="Stage">
<apex:inputField value="{!opp.stageName}"/>
</apex:column>
<apex:column headerValue="Close Date">
<apex:inputField value="{!opp.closeDate}"/>
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>

File Upload

=============VFPages==================
<apex:page controller="fileupload">
 <apex:sectionHeader title="fileupload"/>
  <apex:form enctype="format-data">
   <apex:pageBlock title="upload a file">
    <apex:pageBlockButtons >
         <apex:commandButton value="save" action="{!upload}"/>
    </apex:pageBlockButtons>
    <apex:pageBlockSection showHeader="true" columns="2" id="Block1">
         <apex:pageBlockSectionItem >
           <apex:outputLabel value="file name" for="filename">
               <apex:inputText value="{!Documentname}" id="filename"/>
           </apex:outputLabel>
         </apex:pageBlockSectionItem>
         <apex:pageBlockSectionItem >
          <apex:outputLabel value="file discription" for="file discription">
          <apex:inputFile value="{!DoBody}" fileName="{!Documentname}" id="file">
          </apex:inputFile>
          </apex:outputLabel>
        </apex:pageBlockSectionItem>
        <apex:pageBlockSectionItem >
           <apex:outputLabel value="Description" for="description" />
           <apex:inputTextarea value="{!dodescription}" id="description" />
        </apex:pageBlockSectionItem>
        <apex:pageBlockSectionItem >
          <apex:outputLabel value="Keywords" for="Keywords">
          <apex:inputText value="{!DoKeywords}" id="Keywords"/>
          </apex:outputLabel>
        </apex:pageBlockSectionItem>
        </apex:pageBlockSection>
    </apex:pageBlock>
  </apex:form>
</apex:page>
===========Controller=======================
public with sharing class fileupload {

    public String DoKeywords { get; set; }

    public String dodescription { get; set; }

    public String DoBody { get; set; }

    public String Documentname { get; set; }

   // public String Document {  set; }
    public Document document{
        get{
                if(document == null)
                document= new Document();
                return document;
        }
        set;
    }

    public PageReference upload() {
       // document.AuthorId = UserInfo.getUserId();
        //document.FolderId = UserInfo.getUserId();
        try{
            insert Document;
        }
        catch(DMLException e){
            ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading file'));

        }
        finally {
            DoBody=null;
            Documentname=null;
            Document=new Document();
        }
        ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'File uploaded successfully'));
        return null;
    }

}

Thursday, January 16, 2014

Google Map For Account

=============VFPage============
<apex:page standardController="Account">
<apex:pageBlock >
<head>

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript">


    $(document).ready(function() {
 
        var myOptions = {
            zoom: 40,
            mapTypeId: google.maps.MapTypeId.HYBRID,
            mapTypeControl: true
                }
 
        var map;
        var marker;
 
         var geocoder = new google.maps.Geocoder();
        //var address = "{!Account.ShippingStreet}, " + "{!Account.ShippingCity}, " + "{!Account.ShippingPostalCode}";
        var address = "{!Account.BillingStreet}, " + "{!Account.BillingCity}, " + "{!Account.BillingPostalCode}, " + "{!Account.BillingCountry}";
        var infowindow = new google.maps.InfoWindow({
            content: "<b>{!Account.Name}</b>"
               
                    });

 
    geocoder.geocode( { address: address}, function(results, status) {
        if (status == google.maps.GeocoderStatus.OK && results.length) {
        if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
     
        //create map
        map = new google.maps.Map(document.getElementById("map"), myOptions);
     
        //center map
        map.setCenter(results[0].geometry.location);
       
        //create marker
        marker = new google.maps.Marker({
            position: results[0].geometry.location,
            map: map,
            title: "{!Account.Name}"
        });
       
        //add listeners
        google.maps.event.addListener(marker, 'click', function() {
          infowindow.open(map,marker);
        });
        google.maps.event.addListener(infowindow, 'closeclick', function() {
          map.setCenter(marker.getPosition());
        });
       
      }
     
    } else {
      $('#map').css({'height' : '150px'});
      $('#map').html("Oops! {!Account.Name}'s address could not be found, please make sure the address is correct.");
      resizeIframe();
    }
  });
 
  function resizeIframe() {
    var me = window.name;
    if (me) {
      var iframes = parent.document.getElementsByName(me);
      if (iframes && iframes.length == 1) {
        height = document.body.offsetHeight;
        iframes[0].style.height = height + "px";
      }
    }
  }
 
});
</script>

<style>
#map {
  font-family: Arial;
  font-size:12px;
  line-height:normal !important;
  height:5000px;
  background:transparent;
}
</style>

</head>

<body>
<div id="map"></div>
</body>
</apex:pageBlock>
</apex:page>

==========After===========
1.Go to Expand - Customize - Level 1Customize in Account Page layout
2.Select Account pagelayout click on Edit button
3.In page Layout Drop one selection header
4.Click on vfpages in the select your vfpage name drop into above section and save it

Assignment Rule Throw VFpages

==============VFPages============
<apex:page controller="leadedit" showHeader="false">
<apex:sectionHeader title="Lead Edit" subtitle="{!lead.name}"/>
  <apex:form >
   <apex:pageBlock title="Lead Edit" mode="edit">
    <apex:pageBlockButtons location="top">
     <apex:commandButton value="Save" action="{!mysave}"/>
     <apex:commandButton value="Save & New" action="{!saveandnew}" />
     <apex:commandButton value="Cancel" action="{!mycancel}"/>
    </apex:pageBlockButtons>
    <!--apex:pageBlockButtons location="bottom">
     <apex:commandButton value="Save" action="{!save}"/>
     <apex:commandButton value="Save & New" action="{!save}" />
     <apex:commandButton value="Cancel" action="{!cancel}"/>
    </apex:pageBlockButtons-->
    <apex:pageBlockSection title="Lead Information" columns="2">
     <apex:inputField value="{!lead.OwnerId}" required="false"/>
     <apex:inputField value="{!lead.Phone}" required="false"/>
     <apex:inputField value="{!lead.FirstName}" required="false"/>
     <apex:inputField value="{!lead.MobilePhone}" required="false"/>
     <apex:inputField value="{!lead.LastName}" required="false"/>
     <apex:inputField value="{!lead.Fax}" required="false"/>
     <apex:inputField value="{!lead.Company}" required="false"/>
     <apex:inputField value="{!lead.Email}" required="false"/>
     <apex:inputField value="{!lead.Title}" required="false"/>
     <apex:inputField value="{!lead.Website}" required="false"/>
     <apex:inputField value="{!lead.LeadSource}" required="false"/>
     <apex:inputField value="{!lead.Status}" required="false"/>
     <apex:inputField value="{!lead.Industry}" required="false"/>
     <apex:inputField value="{!lead.Rating}" required="false"/>
     <apex:inputField value="{!lead.AnnualRevenue}" required="false"/>
     <apex:inputField value="{!lead.NumberOfEmployees}" required="false"/>
    </apex:pageBlockSection> <apex:pageBlockSection title="Address Information" columns="2">
    <apex:inputField value="{!lead.Street}" required="false"/>
    <apex:inputField value="{!lead.City}" required="false"/>
    <apex:inputField value="{!lead.State}" required="false"/>
    <apex:inputField value="{!lead.PostalCode}" required="false"/>
    <apex:inputField value="{!lead.Country}" required="false"/>
    </apex:pageBlockSection> <apex:pageBlockSection title="Additional Information" columns="2">
    <apex:inputField value="{!lead.ProductInterest__c}" required="false"/>
    <apex:inputField value="{!lead.CurrentGenerators__c}" required="false"/>
    <apex:inputField value="{!lead.SICCode__c}" required="false"/>
    <apex:inputField value="{!lead.Primary__c}" required="false"/>
    <apex:inputField value="{!lead.NumberofLocations__c}" required="false"/>
    </apex:pageBlockSection>
    <apex:pageBlockSection title="Description Information" columns="1">
    <apex:inputField value="{!lead.Description}" required="false"/>
   </apex:pageBlockSection>
   <apex:pageBlockSection title="Optional">
    <apex:pageBlockSectionItem >
       <apex:inputCheckbox value="{!lead}" >Assign using active assignment rule
         <apex:actionSupport action="{!Action}" event="Onclick"/>
       </apex:inputCheckbox>
    </apex:pageBlockSectionItem>
    </apex:pageBlockSection>
   <apex:detail relatedList="true"/>
  </apex:pageBlock>
 </apex:form>
</apex:page>
==========Controller============
public class leadedit {

    public PageReference Action() {
        AssignmentRule AR = new AssignmentRule();
AR = [select id from AssignmentRule where SobjectType = 'lead' and Active = true limit 1];
Database.DMLOptions dmlOpts = new Database.DMLOptions();
dmlOpts.assignmentRuleHeader.assignmentRuleId= AR.id;
 //lead lead=new lead(Status = 'Open - Not Contacted') ;
lead.setOptions(dmlOpts);
        return null;
    }


    public PageReference cancel() {
        return null;
    }


    public PageReference save() {
        return null;
    }


    public leadedit() {
       lead = new lead(Status = 'Open - Not Contacted');

    }

public lead lead{set;get;}
    public leadedit(ApexPages.StandardController controller) {
    //lead = new lead(Status = 'Open - Not Contacted');
    }
public pageReference mycancel(){
return null;
//page.leadlist;
}
public pageReference mysave(){


insert lead;
return null;
//page.leadlist;
}
public pageReference saveandnew(){
insert lead;
return null;
//page.leadedit;
}
}

Send Emails Throw Vfpages

===========VFPage=============

<apex:page controller="mailcon">
  <style>
.right
{
position:absolute;
right:10px;
width:300px;
background-color:#b0e0e6;

}
.vijay{
background-color:lightblue;
font-size:20px;
color: #FF7C00;
content: "\f00c";
font-family: FontAwesome;
text-decoration: none;
}

</style>
 <apex:form >
 <apex:messages styleClass="vijay"/>
  <apex:pageBlock title="Send mails to user" id="pb">
   <apex:pageBlockSection columns="3">
    <apex:commandButton value="Send Mail" action="{!snd}" rendered="{!sndcon}"/>
    <apex:commandButton value="back" action="{!bck}"/>
    <apex:commandButton value="Send Mass Mail" action="{!sndmail}"/>
   
   </apex:pageBlockSection>
  </apex:pageBlock>
  <apex:pageBlock rendered="{!pbcon}" >
   <apex:pageblockSection >
   <apex:outputText rendered="{!Con}" style="color:blue"> Message Has been sent successfully</apex:outputText><br/>
    <apex:inputText value="{!name}" label="Email Single Address" size="100" style="color:green"/><br/>
   
    <apex:inputTextarea value="{!body}" label="Body"/>
   
      <div class="right">
  <apex:inputFile value="{!attach.body}" filename="{!attach.name}" contentType="appicationtype/ms.word"/><br/>
      </div>
    <apex:commandButton value="Send" action="{!snd1}"/>
   </apex:pageblockSection>
  </apex:pageBlock>
 </apex:form>
</apex:page>

===========Controller===============
public with sharing class mailcon {
   public Attachment attach {get;set;}
    public PageReference bck() {
        return page.mailTomultipulUsers;
        //return null;
    }


    public boolean pbcon { get; set; }

    public boolean sndcon { get; set; }
public mailcon (){
pbcon=false;
sndcon=true;
con=false;}

    public boolean Con { get; set; }

    public PageReference sndmail() {
   
        return null;
    }


    public String body { get; set; }

    public String name { get; set; }
   
 
 

    public  void snd1() {
   
    integer count=0;
        String str=name + ',';
        List<String> li=new List<String>();
        while(str.contains(',')){
       
          count++;
          String[] str1=str.split(',',2);
          system.debug('............'+str1);
              li.add(str1[0]);
          str=str1[1];

         
      }
     
     
       Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

        String[] toAddresses = new String[] {};
           for(integer i=0;i<count;i++){
             toAddresses.add(li[i]);

        }
        String myString = 'StringToBlob';
Blob b = Blob.valueof(myString);
Messaging.EmailFileAttachment efa = new Messaging.EmailFileAttachment();
efa.setFileName('attachment.pdf');
efa.setBody(b);


        mail.setToAddresses(toAddresses);
        mail.setSubject('Email from VF page');
        mail.setPlainTextBody(body);
        mail.setFileAttachments(new Messaging.EmailFileAttachment[] {efa});
       
        try{
       Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
        con=true;
    }
    catch (Exception e){
    ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Sorry... Enter Proper Email Id'));
    }
      name=null;
      body=null;
   
   
     
       
    }


    public PageReference snd() {
     pbcon =true;
   // sndcon=false;
        return null;
    }

}

By Using Standard Controller Save The Record

==========VFPage=========================
<apex:page standardController="custerm__c" showHeader="true" sidebar="false">
  <apex:form >
   <apex:pageBlock title="Customer details">
    <apex:pageBlockButtons >
     <apex:commandButton value="save" action="{!Save}"/>
    </apex:pageBlockButtons>
     <apex:pageBlockSection title="Information">
     <apex:inputField value="{!custerm__c.Name}"/><br/>
     <apex:inputField value="{!custerm__c.Cum__c}"/>
    </apex:pageBlockSection>
    <apex:pageBlockSection title="Personal Inf">
     <apex:inputfield value="{!custerm__c.DOB__c}"/><br/>
     <apex:inputfield value="{!custerm__c.State__c}"/><br/>
     <apex:inputfield value="{!custerm__c.vehicle__c}"/><br/>
     <apex:inputfield value="{!custerm__c.Location__c}"/>
    </apex:pageBlockSection>
   </apex:pageBlock>
  </apex:form>
</apex:page>

Based Picklist Save the record

===========VFPage==============
<apex:page controller="Rahultask">
  <apex:form >
    <apex:pageBlock rendered="{!display}">
      <apex:pageBlockSection >
         <apex:selectList value="{!Names}" label="select Name" size="1">
            <apex:selectOptions value="{!selectName}">
            </apex:selectOptions>
            <apex:actionSupport action="{!change}" event="onchange" />
         </apex:selectList>
      </apex:pageBlockSection>
     </apex:pageBlock>
     <apex:pageBlock rendered="{!display1}" title="ashok" id="pb">
         <apex:pageBlockSection >
             <apex:inputField value="{!obj.Name}"/>
            <apex:inputField value="{!obj.number__c}"/>
            <apex:inputField value="{!obj.ahs__c}"/>
         </apex:pageBlockSection>
         <apex:pageBlockButtons >
            <apex:commandButton value="Save" action="{!Save}"/>
         </apex:pageBlockButtons>
     </apex:pageBlock>
     <apex:pageBlock title="Details" rendered="{!display2}">
        <apex:pageBlockTable value="{!listobj }" var="A">
            <apex:column value="{!A.Name}"/>
           <apex:column value="{!A.number__c}"/>
           <apex:column value="{!A.ahs__c}"/>
        </apex:pageBlockTable>
     </apex:pageBlock>
  </apex:form>
</apex:page>
===========Controller==============
public with sharing class Rahultask {

    public PageReference Save() {
        insert obj;
        display=false;
        display1=false;
        display2=true;
        return null;
    }

   public Rahultask (){
     obj=new NNR__c();
     display=true;
     display1=false;
     display2=false;
   }
    public nnr__c obj{set;get;}
    public PageReference change() {
        display1=true;
        display2 =false;
        return null;
    }
  public boolean display2 { get; set; }
    public boolean display1 { get; set; }
   
    public Boolean display { get; set; }

    public NNR__c listobj {  set; }
   
    public List<NNR__C> getlistobj (){
       List<NNR__c> n= new List<nnr__c> ();
       n=[select name,ahs__c,nnr1__c,number__c from nnr__c where name=:names];
       return n;
    }

    public String ahs { get; set; }

     public String Names {  set; get;}
     public String selectName {set;}
   
     public List<selectoption>  getselectname(){
               List<selectoption> options = new List<selectOption>();
        options.add(new selectOption('','None'));
        for(NNR__c cn:[select id,Name from NNR__c order by Name]){
            options.add(new selectOption(cn.Name,cn.Name));
        }
        return options;

     }
  }

Shortcut key open new window

================VFPage==================
<apex:page controller="onekeypressaction1" showHeader="false" >
 <apex:form >
    <br/><br/><br/>
 <center>
        <a styleclass="h1">
        
        <apex:outputLink accesskey="g" value="http://www.google.com"  target="_blank" styleClass="style1">Go to Google</apex:outputLink><br/><br/>
        <apex:outputLink accesskey="y" value="http://www.youtube.com" target="_blank" styleClass="style2">Go to Youtube</apex:outputLink><br/><br/>
        <apex:outputLink accesskey="t" value="http://www.twitter.com" target="_blank" styleClass="style3">Go to Twitter</apex:outputLink><br/><br/>
        <apex:iframe src="https://c.ap1.visual.force.com/apex/javascript" width="500px" height="300px" scrolling="true" rendered="{!booleanvalue}"/>  <br/><br/><br/>
        </a>
 </center>
 <marquee>
<div style="background-color:; font-size:15px" ><i><b>
1) If you want to go to Google page Just Press Alt+G<br/>
2) If you want to go to Yahoo page Just Press Alt+Y<br/>
3) If you want to go to Twitter page Just Press Alt+T<br/>

 </b></i></div>
</marquee>

    </apex:form>  
     <style>
       div
{
width:380px;
height:px;
background:Blue;
position:relative;
animation:mymove 10s infinite;
//-webkit-animation:mymove 5s infinite; /*Safari and Chrome*/
}
<!-- 
@keyframes mymove
{
from {left:700px;}
to {left:10px;}
} -->


        .style1
        {
        color:blue;
        text-align:left;
        font-size:15pt;
        }
        .style2
        {
        color:Green;
        text-align:left;
        font-size:25pt;
        }
        .style3
        {
        color:Red;
        text-align:left;
        font-size:15pt;
        }
     
     </style>
</apex:page>

===================Controller==================
public with sharing class onekeypressaction1 {
public String getAction() {
    
        booleanvalue = true;
        return null;
    }


    public Boolean booleanvalue { get; set; }
    
    public onekeypressaction1 (){
    
        booleanvalue = false;
    
    }

}

Schema class Example

============VFPage=====================
<apex:page controller="AllObjectsinOrg1" sidebar="false">
  <apex:form >
   <apex:pageBlock id="pgblck">
 
    <apex:outputlabel value="Object Name" for="ObjPickList"/>        
     <apex:selectList value="{!ObjectSelected}" multiselect="false" id="ObjPickList" size="1">
       <apex:selectOptions value="{!ObjList}"/>
       <apex:actionSupport event="onchange"  action="{!fieldsofObject}" rerender="pgblck" />
    </apex:selectList>{!count}<br/><br/>
   
     <apex:outputlabel value="Field Name" for="fldPickList" rendered="{!rendflag}"/>
        <apex:selectList value="{!fldselected}" multiselect="false" id="fldPickList" size="1" rendered="{!rendflag}">
            <apex:selectOptions value="{!FieldList}"/>                                
        </apex:selectList>{!cou}
       
 </apex:pageBlock>
 </apex:form>
</apex:page>

============Controller========================
public class AllObjectsinOrg1 {
 public Integer count{set;get;}
 public Integer cou{set;get;}
 Public string ObjectSelected{get;set;}
 Public string fldselected{get;set;}
 Public Map<String, Schema.SObjectType> AllObjmap;
 Public Map <String, Schema.SObjectField> fieldMap;
 Public boolean rendflag{get;set;}
 Public AllObjectsinOrg1(){
    AllObjmap = New Map<String, Schema.SObjectType>();
    AllObjmap = Schema.getGlobalDescribe();
    System.debug('******All object Names :'+ AllObjmap.keyset());
}
Public List<selectoption> getObjList(){
    List<selectoption> objList = new List<selectoption>();
    for(string s:AllObjmap.keyset()){
        objList.add(new selectoption(s,s));
        count = objList.size();
    }
  return objList;  
 }
 Public List<selectoption> getFieldList(){
    List<selectoption> fldList = new List<selectoption>();
    if(!fieldMap.isEmpty()){
      for(string s:fieldMap.keyset()){
          fldList.add(new selectoption(s,s));
          cou = fldList.size();
      }
      if(fldList.size()== 0)
         fldList.add(new selectoption('--None--','--None--'));
    }
  return fldList;  
 }
  Public void fieldsofObject(){
    fieldMap = New Map <String, Schema.SObjectField>();
    fieldMap = AllObjmap.get(objectSelected).getDescribe().fields.getMap();
    System.debug('###### all fields of object## :' + fieldMap.keyset());
    rendflag = true;
 }
}

Saturday, January 11, 2014

Dynamiclly Adding Rows and Deleting Rows and save into Model

===========VFPage===========================
<apex:page sidebar="false" controller="AddNDeleteRowsDynamically">
 <style>
  .headerRow .TableTitle {
color: DarkBlue!important;
font-size:12pt!important;
font-family:timesnewroman;

}
  .headerRow .TableTitle1 {
color: Chocolate !important;
}
.headerRow .TableTitle2 {
color:Fuchsia !important;
}
</style>


<apex:sectionHeader title="AddNDeleteRowsDynamically"/>
 <apex:form >
   <apex:pageBlock id="pb">
      <apex:pageBlockTable value="{!AddRowlist}" var="A">
         <apex:column headerValue="Name" headerClass="TableTitle">
           <apex:InputField value="{!A.name}"/>
         </apex:column>
         <apex:column headerValue="Text" headerClass="TableTitle1 ">
            <apex:InputField value="{!A.ahs__c}"/>
         </apex:column>
         <apex:column headerValue="Text" headerClass="TableTitle1 ">
            <apex:inputCheckbox value="{!CheckBox}">
            <apex:actionSupport event="onclick" action="{!onclickaction}" />
         </apex:inputcheckbox>
         </apex:column>
         <apex:column headerValue="NNR" headerClass="TableTitle1 ">
            <apex:InputText value="{!A.nnr1__c}" disabled="{!disabled}" />
           
         </apex:column>  
         <apex:column headerValue="Number" headerClass="TableTitle2">
           <apex:inputtext value="{!A.number__c}" disabled="{!disabled}"/>
         </apex:column>
      </apex:pageBlockTable>
      <apex:pageBlockSection >
        <apex:pageBlockSectionItem >
          <apex:commandLink value="Add Row" action="{!AddRow}" reRender="pb"/>
          <apex:commandLink value="Remove Row" action="{!RemoveRow}" reRender="pb"/>
        </apex:pageBlockSectionItem>
     </apex:pageBlockSection>
     <apex:pageBlockButtons >
       <apex:commandButton value="Save" action="{!Save}" reRender="pb"/>
       <apex:commandButton value="Cancel" action="{!Cancel}" reRender="pb"/>
     </apex:pageBlockButtons>
   </apex:pageBlock>
 </apex:form>
</apex:page>
===============Controller===================
public with sharing class AddNDeleteRowsDynamically {
    public boolean checkbox{set;get;}
    public PageReference onclickaction() {
        if(checkbox== true){
            disabled= false;
        }
        else{
            disabled= true;
        }
        return null;
       // return null;
    }


    public Boolean disabled { get; set; }

    public PageReference Cancel() {
        return null;
    }


    public PageReference Save() {
        insert addrowlist;
        addrowlist.clear();
        return null;
    }


    public void RemoveRow() {
        AddRowList.remove(0);
        //return null;
    }


    public void AddRow() {
        Addrowlist.add(new nnr__c());
         if(checkbox== true){
            disabled= false;
        }
        else{
            disabled= true;
        }
     
       
        //return null;
    }

    public AddNDeleteRowsDynamically(){
       string sql='select id,name,ahs__c,nnr1__c,number__c from nnr__c';
       addrows=Database.query(sql);
       AddRowlist=new list<nnr__c>();
       AddRowlist.add(new nnr__C());
       disabled=false;
    }
    public List<nnr__c> AddRows { get; set; }
    public List<nnr__c> AddRowlist { get; set; }
}

Dynamic Search

==============Vfpage=================
<apex:page controller="DynamicAutoSearch1" sidebar="false" showHeader="false" applyHtmlTag="true" applyBodyTag="true" >

 <apex:form >
<apex:messages />

  <apex:pageBlock title="Search Detials" >
      <apex:pageBlockSection >
      <apex:pageBlockSection columns="2">
  
      <apex:outputLabel >First Name:</apex:outputLabel>
      <apex:inputText value="{!fname}">
             <apex:actionSupport event="onkeyup" action="{!LoadData}" reRender="pbtable"/>
       </apex:inputText>
   
   
     <apex:outputLabel >Last Name:</apex:outputLabel>
          <apex:inputText value="{!lname}">
             <apex:actionSupport event="onkeyup" action="{!LoadData}" reRender="pbtable"/>
           </apex:inputText>
   
     <apex:outputLabel >City:</apex:outputLabel>
          <apex:inputText value="{!city}">
             <apex:actionSupport event="onkeyup" action="{!LoadData}" reRender="pbtable"/>
         </apex:inputText>
        
  
     <apex:outputLabel >State:</apex:outputLabel>
          <apex:inputText value="{!state}">
             <apex:actionSupport event="onkeyup" action="{!LoadData}" reRender="pbtable"/>
          </apex:inputText>
     </apex:pageBlockSection> 
     
        
     <apex:pageBlockSection >     
    
     <apex:pageBlockTable value="{!Candidates}" var="c" id="pbtable" style="bgcolor:yellow">
      
    <apex:column value="{!c.First_Name__c}" />
    <apex:column value="{!c.Last_Name__c}"  />
    <apex:column value="{!c.City__c}"  />
    <apex:column value="{!c.State_Province__c}"  />
    <apex:column value="{!c.Country__c}"  />
         
      </apex:pageblocktable>
   </apex:pageBlockSection>
   </apex:pageBlockSection>
  </apex:pageblock>
 

 </apex:form>
 </apex:page>
=======================================
public with sharing class DynamicAutoSearch1 {
    public DynamicAutoSearch1 (){
        
        can =[select id,First_Name__c,Last_Name__c,State_Province__c,City__c,Country__c From Candidate__c];
    }

    public List<Candidate__c> Can{ get; set; }
    public String state { get; set; }
    public String city { get; set; }
    public String lname { get; set; }    
    public String fname { get; set; }    
    public List<Candidate__c> getCandidates (){    
        return can;
    }    
   
    public PageReference LoadData() {
        if(fname != null && lname == '' && city == '' && state == '' ){
            can =[select id,First_Name__c,Last_Name__c,State_Province__c,City__c,Country__c From Candidate__c where first_name__c Like:(fname+'%')];
        }
        else if(fname != null && lname != '' && city == '' && state == '' ){
            can =[select id,First_Name__c,Last_Name__c,State_Province__c,City__c,Country__c From Candidate__c where Last_Name__c Like:(lname +'%') AND first_name__c Like:(fname+'%') ];
        }

        
        else if(fname != null && lname == '' && city != '' && state == '' ){
            can =[select id,First_Name__c,Last_Name__c,State_Province__c,City__c,Country__c From Candidate__c where first_Name__c Like:(fname +'%') AND city__c Like:(city+'%')];
        }
        else if(fname != null && lname == '' && city == '' && state != '' ){
            can =[select id,First_Name__c,Last_Name__c,State_Province__c,City__c,Country__c From Candidate__c where first_Name__c Like:(fname +'%') AND State_Province__c Like:(state+'%')];
        }
        else if(fname != null && lname != '' && city != '' && state == '' ){
            can =[select id,First_Name__c,Last_Name__c,State_Province__c,City__c,Country__c From Candidate__c where first_Name__c Like:(fname +'%') AND Last_Name__c Like:(lname+'%') AND city__c Like:(city+'%')];
        }
        else if(fname != null && lname != '' && city == '' && state != '' ){ 
            can =[select id,First_Name__c,Last_Name__c,State_Province__c,City__c,Country__c From Candidate__c where first_Name__c Like:(fname +'%') AND Last_Name__c Like:(lname+'%') AND State_Province__c Like:(state+'%')];
        }
        else if(fname == null && lname != '' && city == '' && state == '' ){
            can =[select id,First_Name__c,Last_Name__c,State_Province__c,City__c,Country__c From Candidate__c where Last_name__c Like:(lname+'%')];
        }
        else if(fname == null && lname != '' && city != '' && state == '' ){
            can =[select id,First_Name__c,Last_Name__c,State_Province__c,City__c,Country__c From Candidate__c where Last_name__c Like:(lname+'%') AND city__c Like:(city+'%')];
        }
        else if(fname == null && lname != '' && city == '' && state != '' ){
            can =[select id,First_Name__c,Last_Name__c,State_Province__c,City__c,Country__c From Candidate__c where Last_name__c Like:(lname+'%') AND State_Province__c Like:(state+'%')];
        }
        else if(fname == null && lname != '' && city != '' && state != '' ){
            can =[select id,First_Name__c,Last_Name__c,State_Province__c,City__c,Country__c From Candidate__c where Last_name__c Like:(lname+'%') AND State_Province__c Like:(state+'%') AND city__c Like:(city+'%')];
        }
        else if(fname == null && lname == '' && city != '' && state == '' ){
            can =[select id,First_Name__c,Last_Name__c,State_Province__c,City__c,Country__c From Candidate__c where city__c Like:(city+'%')];
        }
        else if(fname == null && lname == '' && city != '' && state != '' ){
            can =[select id,First_Name__c,Last_Name__c,State_Province__c,City__c,Country__c From Candidate__c where city__c Like:(city+'%') AND State_Province__c Like:(state+'%')];
        }
        else if(fname == null && lname == '' && city == '' && state != '' ){
            can =[select id,First_Name__c,Last_Name__c,State_Province__c,City__c,Country__c From Candidate__c where State_Province__c Like:(state+'%')];
        }
        else if(fname != null && lname != '' && city != '' && state != '' ){
            can =[select id,First_Name__c,Last_Name__c,State_Province__c,City__c,Country__c From Candidate__c where first_Name__c Like:(fname +'%') AND Last_Name__c Like:(lname+'%') AND State_Province__c Like:(state+'%') AND city__c Like:(city+'%')];
        }
        else if(fname == null && lname == '' && city == '' && state == '' ){
            can =[select id,First_Name__c,Last_Name__c,State_Province__c,City__c,Country__c From Candidate__c ];
        }
    /*    else if(fname == '' && lname != null){
            can =[select id,First_Name__c,Last_Name__c,State_Province__c,City__c,Country__c From Candidate__c where Last_Name__c Like:(lname +'%')];
        }
        else if(fname != null && lname != null){
            can =[select id,First_Name__c,Last_Name__c,State_Province__c,City__c,Country__c From Candidate__c where Last_Name__c Like:(lname +'%') AND first_name__c Like:(fname+'%') ];
        }*/
       /* else 
         Apexpages.addmessage(new apexpages.message(apexpages.severity.Error,'Not matching Record'));*/
        return null;
    }   
}

Checkboxs

https://c.na15.visual.force.com/apex/CheckBoxDelete1

====================VFPage==============================
<apex:page controller="picklistusingwrapper" sidebar="false">
    <apex:form >
        <apex:pageBlock id="pgblock" title="Select Student" >
            <apex:pageBlockTable value="{!Studentlist}" var="s" >
                <apex:column >
                    <apex:facet name="header">
                        <apex:inputCheckbox onclick="selectall()" />
                    </apex:facet>
                    <apex:inputCheckbox value="{!s.checkflag}" />
                </apex:column>
                <apex:column value="{!s.stud.Name}" >                  
                </apex:column>
                <apex:column value="{!s.stud.Mobile_no__c}" >
                </apex:column>
                <apex:column value="{!s.stud.C_Email_id__c}" >
                </apex:column>
               </apex:pageblockTable>
            <apex:commandButton value="Delete" action="{!deleteaction}" reRender="pgblock"/>
        </apex:pageBlock>
        <apex:actionFunction name="selectallsri" action="{!selectallmethod}" reRender="pgblock"/>
    </apex:form>
    <script type="text/javascript">
        function selectall(){
            selectallsri();
        }
   
    </script>
</apex:page>

==========Controller======================
public with sharing class picklistusingwrapper {

  public PageReference deleteaction() {
        List<Candidate__c> srilist = new List<Candidate__c>();
        for(wrapperclass ws: studlist){
            if(ws.checkflag == true){
                srilist.add(ws.stud);
            }
        }
        delete srilist;
        return null;
    }

    public List<wrapperclass> studlist{get; set;}

    public boolean checkbox{get; set;}

    public picklistusingwrapper (){
        checkbox = false;
    }

    public void selectallmethod(){
        if(!checkbox){
            checkbox = true;
        }
        else{
            checkbox = false;
        }    
    }
    public List<wrapperclass> getStudentlist() {
        studlist = new List<wrapperclass>();
        for(Candidate__c ss: [select id,name,Mobile_no__c,C_Email_id__c from Candidate__c]){
            if(!checkbox){
                studlist.add(new wrapperclass(ss,false));
            }
            else{
                studlist.add(new wrapperclass(ss,true));
            }
        }
        return studlist;
    }
    public class wrapperclass{
        public Candidate__c stud{get; set;}
        public boolean checkflag{get; set;}
       
        public wrapperclass(Candidate__c s,boolean flag){
            stud = s;
            checkflag = flag;
        }
   
    }
}