Friday, March 21, 2014

How to Write Pagination of visualforce page ?

MEthod 1:

:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::VISUAL FORCE PAGE :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
<apex:page controller="Paginationclass">
  <apex:form >
        <apex:pageBlock id="pb">
            <apex:pageBlockTable value="{!opportunities}" var="o">
                <apex:column value="{!o.name}"/>
                <apex:column value="{!o.closedate}"/>
            </apex:pageBlockTable>
         
            <apex:commandButton rendered="{!setCon.hasPrevious}" value="first" action="{!setCon.first}" reRender="pb"/>
            <apex:commandButton rendered="{!setCon.hasPrevious}" value="Previous" action="{!setCon.previous}" reRender="pb"/>
            <apex:outputText rendered="{!(setCon.pageNumber * setCon.pageSize) < setCon.ResultSize}" value="{!setCon.pageNumber * setCon.pageSize} Of {!setCon.ResultSize}"></apex:outputText>
            <apex:outputText rendered="{!(setCon.pageNumber * setCon.pageSize) >= setCon.ResultSize}" value="{!setCon.ResultSize} Of {!setCon.ResultSize}"></apex:outputText>
         
            <apex:commandButton rendered="{!setCon.hasNext}" value="next" action="{!setCon.next}" reRender="pb"/>
         
            <apex:commandButton rendered="{!setCon.hasNext}" value="last" action="{!setCon.last}" reRender="pb"/>
           <apex:actionStatus id="status" >
              <apex:facet name="start">
                <apex:image value="/img/loading32.gif" style="height: 15px;"></apex:image>
              </apex:facet>
           </apex:actionstatus>
        </apex:pageBlock>
    </apex:form>
</apex:page>

======================CONTROLEER===============
public class Paginationclass{
    public ApexPages.StandardSetController setCon {
        get {
            if(setCon == null) {
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
                      [select name,closedate from Opportunity]));
            }
            return setCon;
        }
        set;
    }

    // Initialize setCon and return a list of records
 
    public List<Opportunity> getOpportunities() {
         setCon.setpagesize(5);
         return (List<Opportunity>) setCon.getRecords();
    }
}


METHOD -2
==============VISUAL FORCE PAGE========================

<apex:page controller="paginationController">
 <apex:form >
   <apex:pageBlock >
    <apex:pageBlockButtons >
        <apex:commandButton value="Previous" action="{!Previous}" reRender="table" status="status"/>
          <apex:commandButton value="Next" action="{!Next}" reRender="table" status="status"/>
            <apex:actionStatus id="status" >
              <apex:facet name="start">
                <apex:image value="/img/loading32.gif" style="height: 15px;"></apex:image>
              </apex:facet>
           </apex:actionstatus>
    </apex:pageBlockButtons>
     <apex:pageblockTable value="{!lstAcct}" var="item" id="table">
        <apex:column value="{!item.name}"/>
        <apex:column value="{!item.Accountnumber}"/>
        <apex:column value="{!item.Phone}"/>
    </apex:pageblockTable>
  </apex:pageBlock>
 </apex:form>
</apex:page>
==================CONTROLLER==================
public class paginationController {
     Integer recordLimit = 10;
     Integer offSetLimit = 0;
    Public List<Account> lstAcct {
         get{
                 lstAcct = [select Id,name,Accountnumber,phone from Account  Limit :recordLimit OFFSET :offSetLimit ];
                 return lstAcct;
             }set;
     }
     
     public paginationController (){
       
     }
     
     Public pagereference Next(){
         if(lstAcct.size()!=offSetLimit ){
                   offSetLimit +=  4;
                   system.debug('@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@'+offSetLimit );
         }
       
         else{
          ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Warning,'No Records to Display'));
         }
         return null;
     }
     
     Public pagereference Previous(){
         if(offSetLimit > 0)
             offSetLimit = offSetLimit - 4;
         return null;
     }
}

Friday, March 14, 2014

Enable account team member 
follow navigation  setup==>customize==>account====>Account teams .
once you enable this accountteam member object is added to related list of account.
2) create one check box VPA on account object.
now the requirement is:

create one record in account (call parent record) mention VPA enable and don't select parent look up field.
create  one more record in account(call child) uncheck VPA and select (parent record) as parent for this child record using look up.
here VPA is enable means that record is parent other wise it's a child record...

Need to be achieve:
1) once you create a child record then owner of parent record should be add to child   related accountteam member.(parent owner should be insert as accounteam meber to child)
2) if you change the owner in parent it should replace the old owner with new onwer.


Answer :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::;

trigger AccTrigger1 on Account (after update) {
      List<AccountTeamMember> atms=new List<AccountTeamMember>();
      List<Id> ids=new List<Id>();
    for(Account a:Trigger.old)
    {
      if(a.VPA__c==true)
      {
       List<Account> childs=[SELECT id FROM Account where parentid=:a.id];
          for(Account childacc:childs)
          {
               ids.add(childacc.id);
          }
        atms=[SELECT AccountId,TeamMemberRole,UserId FROM AccountTeamMember where AccountId IN:ids ];
        for(Account a1:Trigger.new)
        {
         
             Account newoi=[SELECT OwnerId FROM Account where id=:a1.id];
              for(AccountTeamMember atm:atms)
              {
                   AccountTeamMember newatm=new  AccountTeamMember();
                   newatm.UserId=newoi.OwnerId;
                   newatm.TeamMemberRole=atm.TeamMemberRole;
                   newatm.AccountId=atm.AccountId;
                   insert newatm;
                   delete atm;
              }
        
         }
      }
    }
    
    
}



Monday, March 10, 2014

Login Page

===========VFPAGE===================
<apex:page sidebar="false" controller="task4">
  <apex:form id="fm">
    <apex:pageBlock id="pb" title="LoginPage" tabStyle="LOginpage__c">
     <apex:pageMessages ></apex:pageMessages>
       <apex:panelGrid bgcolor="color:red" columns="1">
         <apex:outputtext >Enter User Name</apex:outputtext>
         <apex:inputtext value="{!UName}" id="un" />
         <apex:outputtext >Enter PossWord</apex:outputtext>
         <apex:inputsecret value="{!UPW}" id="pw" />
       </apex:panelGrid>
       <apex:commandButton value="Login" action="{!Login}" id="LP"/>
    </apex:pageBlock>
  </apex:form>
</apex:page>
============CONTROLLER=====================
public with sharing class task4 {
    public  List<LoginPage__c> obj{get;set;}
    public PageReference Login() {
        obj= new List<LoginPage__c>();
        if(UName!=null && UName!=''){
                obj=[select id,name,password__c from LoginPage__c where name=:UName limit 1];
                if(obj.size()>0){
                   for(LoginPage__c log:obj){
                      if(Uname==log.name){
                      }
                      else{
                         Apexpages.addmessage(new Apexpages.message(Apexpages.severity.Warning,'UserName is wrong '));
                      }
                      if(UPW== log.password__c){
                       
                      }
                      else{
                         Apexpages.addmessage(new Apexpages.message(Apexpages.severity.Error,'Password is Wrong '));
                      }
                   }// end of for loop
                }
        }
        else{
             Apexpages.addmessage(new Apexpages.message(Apexpages.severity.Warning,'Enter UserName '));
        }
        for(LoginPage__c log:obj){
                if(UName==log.name && UPW==log.password__c){
                          PageReference pr= new PageReference('https://ap1.salesforce.com/'+log.id);
                          return pr;
                }    
       }
       return null;
    }


    public string UPW { get; set; }

    public string UName { get; set; }
}

Edit and Delete functionality............

==================VFPAGE=============
<apex:page sidebar="false" controller="task3b">
<style Type="text/css">
  .ashok{
      background-color:blue;
  }
</style>
  <apex:form id="f">
    <apex:pageBlock title="Edit/Delete" mode="Edit" tabStyle="Book__c">
       <apex:pageblockTable var="bk" value="{!bkList}">
           <apex:column headerValue="Action">
              <apex:outputLink title="" value="/{!bk.id}/e?retURL=/apex/{!$CurrentPage.Name}">Edit</apex:outputLink>  &nbsp;&nbsp;
              <a href="javascript:if (window.confirm('Are you sure?')) DeleteRecord('{!bk.Id}');" style="font-weight:bold">Del</a>
           </apex:column>
           <apex:column value="{!bk.name}"/>
           <apex:column value="{!bk.Price__c}"/>
       </apex:pageblockTable>
       <apex:actionFunction name="DeleteRecord" action="{!Del}" reRender="f" >
          <apex:param value="" name="Rec" assignTo="{!bl}"/>
       </apex:actionfunction>
     </apex:pageBlock>
  </apex:form>
</apex:page>
==========CONTROLLER===============
public with sharing class task3b {

    public void Del() {
        if(bl==null){
            return ;
        }  
        book__c bl1=null;
        for(book__c bks:bklist){
           if(bks.id==bl){
             bl1=bks;
           }
        }
        if(bl1!=null){
           delete bl1;
        }
        AshokMehtod();
    }

    public void AshokMehtod(){
       bkList=[select id,name,author__c,price__c from book__c];
    }
    public task3b(){
       AshokMehtod();
    }
    public string bl{set;get;}
    public List<book__c> bkList {get; set;}
     
}

Login Page for New User

==============vfpagecode=================
<apex:page sidebar="false" controller="Loginpage">
  <script>
     function validate(){
             
         var  UnameVal= document.getElementById("{!$Component.f.pb.ps.un}").value;
         var  UNnameVal= document.getElementById("{!$Component.f.pb.ps.nn}").value;
         var  UEmailVal= document.getElementById("{!$Component.f.pb.ps.em}").value;
         var  UPWVal= document.getElementById("{!$Component.f.pb.ps.pw}").value;
         var  UCPVal= document.getElementById("{!$Component.f.pb.ps.cp}").value;
         if(UnameVal==''){
            alert('Please Enter userName');
         }
         else if(UNnameVal==''){
           alert('please Enter nickName');
         }
         else if(UEmailVal==''){
            alert('Enter your Email Id');
         }
         else if(UPWVal==''){
            alert('Enter your PW');
         }
         else if(UCPVal==''){
             alert('Enter your conformPW');
         }
         else if(UCPVal!=UPWVal){
             alert('please reenter ur cpw');
         }
         else{
             s();
         }    
       
           
                                   
       }    
       
 </script>
  <apex:form id="f">
      <apex:actionFunction action="{!save}" name="s"/>
      <apex:pageBlock title="LoginPage" id="pb" >
        <apex:pageBlockSection columns="1" id="ps" >
             <apex:inputtext value="{!Log.name}" id="un"/>
             <apex:inputtext value="{!Log.NickName__c}" id="nn"/>
             <apex:inputtext value="{!Log.Email__c}"  id="em"/>
             <apex:inputsecret value="{!Log.password__c}" id="pw"/>
             <apex:inputsecret value="{!Log.ConformPassword__c}" id="cp"/>
        </apex:pageBlockSection>
        <apex:pageblockButtons location="bottom">
             <apex:commandButton value="Insert"  onclick="validate()" ReRender="pb"/>
        </apex:pageblockButtons>
    </apex:pageBlock>
  </apex:form>
</apex:page>
=============controller==================
public with sharing class Loginpage {

    public void Save() {
        insert log;
        ApexPages.Message myMsg=new ApexPages.Message(ApexPages.Severity.Info,'Record Inserted');
        ApexPages.addMessage(myMsg);
        log.clear();
    }

   public Loginpage(){
     log=new LoginPage__c();
   }
   public LoginPage__c log{get;set;}
}

TAB PANEL USAGE

==============================VFPAGE==================
<apex:page controller="TaskClass" sidebar="false" id="Thepage">
 <style>
   .red{ background-color:Red;
   }
   .blue{
        Background-color:blue;
   }
   .yellow{
        Background-color:yellow;
    }    
 </style>
 <script>
     function validate(){
               
         var  Bname= document.getElementById("{!$Component.f.pb.pg.bn}").value;  
         var  Bauthor= document.getElementById("{!$Component.f.pb.pg.ba}").value; 
         var  Bprice= document.getElementById("{!$Component.f.pb.pg.bp}").value; 
         if(Bname==''){
            alert('Please Enter userName');
         }
         else if(Bauthor==''){
           alert('please Enter nickName');
         }
         else if(Bprice==''){
            alert('Enter your Email Id');
         }
         else{
             s();
         }     
                               
       }     
         
 </script>
 <apex:messages />
  <apex:tabPanel switchType="client" styleClass="background-color:skyblue" id="thetab" >
     <apex:tab label="BookList" styleClass="red" id="booklist" labelWidth="170" reRender="Bls" >
        <apex:form >
         <apex:actionFunction action="{!Record}" name="s"/>
           <apex:pageBlock title="All Records in List" id="tab"  >
                 <apex:pageblockTable var="BL" value="{!BookList}" >
                 <apex:column value="{!BL.name}" style="color:blue" />
                 <apex:column value="{!BL.Author__c}" style="color:orange"/>
                 <apex:column value="{!BL.Price__c}" style="color:PaleVioletRed"/>
               </apex:pageblockTable>
           </apex:pageBlock>>
         </apex:form>
     </apex:tab>
     <apex:tab label="Serch Book" id="Srbook" labelWidth="170" styleClass="blue" style="color:block">
      <apex:form >
        <apex:pageBlock title="serch book" id="page">
          <apex:outputtext > Enter Book Name </apex:outputtext>
          <apex:inputtext value="{!BookName}"/>
          <apex:commandButton value="Search" action="{!SerchBook}" reRender="page" status="status"/>
          <apex:actionStatus id="status" startText="Requesting....."></apex:actionStatus>
          <apex:pageBlockSection title="Book Details">
             <apex:pageblockTable value="{!SerchList}" var="SL" >
                <apex:column value="{!SL.name}"/>
                <apex:column value="{!SL.Author__c}"/>
                <apex:column value="{!SL.Price__c}"/> 
             </apex:pageblockTable>
          </apex:pageBlockSection>
        </apex:pageBlock>
       </apex:form>  
     </apex:tab>
     <apex:tab label="Insert Record" labelWidth="170" styleClass="yellow" id="Insert">
       <apex:form id="f">
          <apex:pageblock title="Insert Record" id="pb">
             <apex:panelGrid id="pg" >      
                Book name    <apex:inputtext value="{!BName}" id="bn"/>
                     Author  <apex:inputtext value="{!BAuthor}" id="ba"/>
                     price   <apex:inputtext value="{!Bprice}" id="bp"/>
                   <apex:commandButton value="Insert" onclick="validate()"/>
             </apex:panelGrid>  
          </apex:pageblock>
       </apex:form>
     </apex:tab>
   </apex:tabPanel>
 </apex:page>

=================================CONTROLLER=========================
public with sharing class TaskClass {

    public decimal Bprice { get; set; }

    public String BAuthor { get; set; }

    public string BName { get; set; }
        public TaskClass (){
           
        }
    public void Record (){
       book__c obj =new Book__c();
       obj.name=bname;
       obj.author__c=Bauthor;
       obj.price__c=Bprice;
       insert obj;
       ApexPages.Message myMsg=new ApexPages.Message(ApexPages.Severity.Info,'Record Inserted');
       ApexPages.addMessage(myMsg);
    }
    //http://mysfdcblog.blogspot.in/2012/09/tab-panel.html
    
    public string serchlist{set;}
    public List<Book__c> getserchlist(){
       try{
           List<Book__c> sls=[select name,author__c,price__c from book__c where name=:Bookname];
           return sls;
       }
       catch(Exception e){
         
       ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Info,'No Record for'+Bookname));
       return null;
       }
    }
    public PageReference SerchBook() {
       //book__c sls=[select name,author__c,price__c from book__c where name=:BookName];
       return null;
    }


    public String BookName { get; set; }

    public String BookList {  set; }
    public List<book__c> getBookList(){
       List<book__c> books=[select name,author__c,price__c from book__c];
       return books;
    }
}















Search and Display Record

===============VFPAGE============
<apex:page controller="SearchRecord" showHeader="true" tabStyle="Company__c" sidebar="false">
  <apex:form >
  <apex:messages />
   <apex:pageBlock title="Search and Display Records" mode="edit" id="pb1">
     <apex:pageBlockSection >
        <apex:pageBlockSectionItem >
           <apex:outputText value="Enter Record Name"/>
             <apex:inputText value="{!Name}"/>
        </apex:pageBlockSectionItem>
        <apex:pageBlockSectionItem >
           <apex:commandButton value="search" action="{!search}" />
        </apex:pageBlockSectionItem>
     </apex:pageBlockSection>
   </apex:pageBlock>
  </apex:form>
      <apex:form >
        <apex:pageBlock title="Display" rendered="{!dsp}" id="pb">
          <apex:pageBlockSection >
              <apex:dataTable var="nnr" value="{!Rec}" cellpadding="4" border="1">
              <apex:column >
              <apex:facet name="header"><b>Name</b></apex:facet>
              <apex:commandLink reRender="detail">{!nnr.name}
              <apex:param name="id" value="{!nnr.id}"/>
           </apex:commandLink>
          </apex:column>
            <apex:column >
       <apex:facet name="header"><b>Email</b></apex:facet>
         {!nnr.email__c}
     </apex:column>
     </apex:datatable>
     </apex:pageBlockSection>
     </apex:pageBlock>
    </apex:form>
    </apex:page>
========CONTROLLER=============
public with sharing class SearchRecord {


    public String Rname { get; set; }
    PUBLIC boolean dsp{set;get;}
    public string Rec{set;}
    public List<company__c> getRec(){
         List<company__c> cm=[select id,name,Email__c from company__c where name=:name ];
        return cm;
    }
   

    public PageReference search() {
       try{
            dsp=true;
            company__c cmp=[select id,name from company__c where name=:Name ];
            //Rname=cmp.name;
        }
      catch(Exception e){
       dsp=false;
      Apexpages.addMessage(new apexpages.Message(apexpages.severity.ERROR,'norecords in list'));
      }
        return null;
    }


    public String Name { get; set; }
}

RENDERD TAG USAGE FOR VISUALFORCE PAGE

====================VISUALFORCEPAGE==============
<apex:page controller="RenderdClass" showHeader="false">
  <apex:form >
    <apex:pageBlock >
      <apex:pageBlockSection rendered="{!page1}">
        <apex:inputtext value="{!obj.name}"/><br/>
         <apex:inputtext value="{!obj.LName__c}"/><br/>
          <apex:commandButton value="Next" action="{!NextPage1}"/>
      </apex:pageBlockSection>
      <apex:pageBlockSection rendered="{!page2}">
        <apex:inputtext value="{!obj.Email__c}"/><br/>
         <apex:inputtext value="{!obj.Number__c }"/><br/>
          <apex:commandButton value="next" action="{!Nextpage2}"/><br/>
           <apex:commandButton value="previous" action="{!PPage1}"/>
      </apex:pageBlockSection>
      <apex:pageBlockSection rendered="{!page3}">
        <apex:inputtext value="{!obj.Phone__c}"/><br/>
          <apex:commandButton value="Previous" action="{!PPage2}"/><br/>
            <apex:commandButton value="save" action="{!save}"/><br/>
              <apex:commandButton value="Save&New" action="{!SaveNew}"/><br/>
              <apex:commandButton value="cancel" action="{!Cancel}"/><br/>
      </apex:pageBlockSection>
    </apex:pageBlock>
  </apex:form>
</apex:page>
==============CONTROLLER=================
public with sharing class RenderdClass {

    public PageReference SaveNew() {
        page1=true;
        page2=false;
        page3=false;
         insert obj;
        return null;
    }


    public PageReference Cancel() {
        page1=true;
        page2=false;
        page3=false;
        return null;
    }


    public void save() {
            insert obj;
         ApexPages.Message myMsg=new ApexPages.Message(ApexPages.Severity.Info,'Record Inserted');
         ApexPages.addMessage(myMsg);
            //return null;
    }


    public PageReference PPage2() {
        page1=false;
        page2=true;
        page3=false;
        return null;
    }


    public PageReference PPage1() {
        page1=true;
        page2=false;
        page3=false;
        return null;
    }


    public PageReference Nextpage2() {
        page1=false;
        page2=false;
        page3=true;
        return null;
    }


    public NNR__c obj{set;get;}
    public RenderdClass(){
        obj=new NNR__c();
        page1=true;
        page2=false;
        page3=false;
    }
    public PageReference NextPage1() {
        if(obj.name==null ||obj.LName__c==null ){
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.CONFIRM,'Please enter Account number'));
        }
        else{
        page1=false;
        page2=true;
        page3=false;
        }
        return null;
    }
    public Boolean page1 { get; set; }
    public Boolean page2 { get; set; }
    public Boolean page3 { get; set; }


}

How To Use PopUp window for Update record and delete





=======VFPAGE============================
<apex:page sidebar="false" controller="Pouup" id="Thepage">
  <style type="text/css">
    .puoup{
           background-color:white;
           border width:3px;
           border-style: solid;
            z-index: 9999;
            left: 50%;
            padding:10px;
            position: absolute;
            width: 500px;
            margin-left: -250px;
            top:80px;
    }
    .poupblog{
            background-color:Red;
            opacity: 0.20;
            filter: alpha(opacity = 70);
            position: absolute;
            width: 100%;
            height: 100%;
            top: 0;
            left: 0;
            z-index: 9998;
    }
  </style>
  <apex:form >
    <apex:messages />
    <Center>
      Select book
      <apex:selectList value="{!bks}" size="1" id="sl">
        <apex:selectOptions value="{!bklist}"></apex:selectOptions>
      </apex:selectList>
      <apex:commandButton value="Showvalue" action="{!puouup}" reRender="op"/>
    </center>
    <apex:pageblock id="pb">
       <apex:pageblocktable var="bk" value="{!AllBks}" id="pbt">
         <!--apex:column width="100">
         <apex:commandLink value="Edit" />&nbsp;
         <apex:commandLink value="delete" action="{!del}"/>
         </apex:column>
         -->
         <apex:column headerValue="Book Name" >
           <apex:outputtext value="{!bk.name}"/>
         </apex:column>
         <apex:column headerValue="Book Author" >
           <apex:outputtext value="{!bk.Author__c}"/>
         </apex:column>
         <apex:column headerValue="Book price" >
           <apex:outputtext value="{!bk.Price__c}"/>
         </apex:column>
       </apex:pageblocktable>
    </apex:pageblock>
    <apex:outputpanel id="op">
     <apex:outputpanel styleClass="poupBlog" layout="block" rendered="{!displayPopUp}" />
     <apex:outputpanel styleClass="puoup" layout="block" rendered="{!displayPopUp}">
     <apex:pageBlock >
        <apex:panelgrid >
          Book Name   <apex:inputtext value="{!BName}"/>
          Book Author <apex:inputtext value="{!BAuthor}"/>
          Book price  <apex:inputtext value="{!BPrice}"/>
        </apex:panelgrid>
        <apex:commandButton value="Cancel" action="{!cancel}" reRender="op,pb,pbt,sl"/>
        <apex:commandButton value="update" action="{!upRec}" reRender="op,pb,pbt,sl"/>
         <apex:commandButton value="Delete" action="{!Deletez}" reRender="op,pb,pbt,sl"/>
     </apex:pageBlock>
    </apex:outputpanel> 
    </apex:outputpanel>
  </apex:form>
</apex:page>
==========CONTROLLER=============
public with sharing class Pouup {

    public PageReference Deletez() {
            displayPopUp=false;
            Book = [SELECT Id,Name,price__c,Author__c FROM Book__c where id =: bks];
            book.Name = bname;
            book.Price__c = bprice;
            book.Author__c =bAuthor;
            try{
                 delete book;
                 apexPages.addMessage(new ApexPages.message(ApexPages.severity.Error,'.Sorry!.......'));
   
           }
           catch(Exception e){
                 apexPages.addMessage(new ApexPages.message(ApexPages.severity.Error,'.Sorry!.......'));
           }
           return null;
    }


    public PageReference cancel() {
        displayPopUp=false;
        return null;
    }


    public PageReference upRec() {
         Book = [SELECT Id,Name,price__c,Author__c FROM Book__c where id =: bks];
            book.Name = bname;
            book.Price__c = bprice;
            book.Author__c =bAuthor;
            try{
                 update book;
                 displayPopUp=false;
   
           }
           catch(Exception e){
                 apexPages.addMessage(new ApexPages.message(ApexPages.severity.Error,'.Sorry!.......'));
           }
        return null;
    }


    public Decimal BPrice { get; set; }

    public String BAuthor { get; set; }

    public String BName { get; set; }

    public boolean displayPopUp { get; set; }

    public PageReference del() {
        return null;
    }


    public String AllBks {  set; }
    public List<Book__c> getAllBks(){
       List<Book__c> abs=[select id,name,author__c,price__c from book__c ];
       return abs;
    }

    public PageReference puouup() {
            displayPopUp=true;
            Book = [SELECT Id,Name,price__c,Author__c FROM Book__c where id =: bks];
            bname= book.Name ;
            bprice=book.Price__c ;
            bAuthor=book.Author__c;
        return null;
    }

    book__c book;
    list<book__c> book1;
    public String bklist {  set; }

    public String bks { get; set; }
    public list<selectoption> getbklist(){
        List<selectOption> bks= new List<selectOption>();
        bks.add(new selectOption('<---None-->','<--None-->'));
        for(BOok__c Bl:[select id,name from Book__c]){
           bks.add(new selectOption(bl.id,bl.name));
        }
        return bks;
    }
}

Sending Emails FOr multiple users

=========================VFPAGE=======================
<apex:page controller="Emailclass" sidebar="false">
 <apex:form >
 <apex:sectionHeader title="Send Emails To multiple Users"/>
   <apex:pageBlock id="pb">
     <apex:pageBlockSection >
        <apex:inputText label="To Adress" value="{!Name}" size="80"/><br/>
        <apex:inputText label="Subject" value="{!Subject}"/><br/>
        <apex:inputTextarea label="Body" value="{!Body}" rows="15" cols="100" style="background:yellow"/><br/>
        <apex:commandButton value="Send" action="{!Send}" /><br/>
      </apex:pageBlockSection>
   </apex:pageBlock>
 </apex:form>
</apex:page>

==============controller======================
public with sharing class Emailclass {

    public PageReference Send() {
        string names=name+',';
        Integer count=0;
        List<string> str=new List<string>();
        while(names.contains(',')){
           count++;
           string[] str1=names.split(',',2);
           str.add(str1[0]);
           system.debug(''+str1);
           names=str1[1];
        }
   
        Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
           string[] toaddresses=new string[]{};
           for(integer i=0;i<count;i++){
              toaddresses.add(str[i]);
           }
        mail.setToAddresses(toAddresses);
        mail.setSubject(subject);
        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;
      subject=null;
      body=null;
   

        return null;
    }


    public String Body { get; set; }

    public String Subject { get; set; }

    public String Name { get; set; }
}

Automatically Save the Record

==========VFPAGE=========================
<apex:page sidebar="false" controller="AutoSave">
 <apex:form id="fm">
    <script>
        window.setTimeout(recursivecall,40000);
        function recursivecall(){
              window.setTimeout(recursivecall,40000);
              autosave();
        }
        function ashok(){
           var BN= document.getElementById("{!$Component.fm.pb.ps.pg.bn}").value;
           var BN1= document.getElementById("{!$Component.fm.pb.ps.pg.ba}").value;
           var BN2= document.getElementById("{!$Component.fm.pb.ps.pg.bp}").value;
           if(BN==''){
             alert('nnr');
           } 
        }
  </script>
  <apex:pageBlock title="AutoSave" id="pb">
  <apex:actionFunction name="autosave" action="{!ASMethod}" status="savestatus" reRender="AS"/>
    <apex:pageBlockSection id="ps">
      <apex:actionStatus id="savestatus">
          <apex:facet name="start"> Auto Saving....<img src="/img/loading.gif"/> </apex:facet>
    </apex:actionStatus>

      <apex:panelGrid onclick="ashok()" id="pg">
        <apex:actionSupport event="onclick"  id="AS"  />
        BOOk name    <apex:inputText value="{!log.name}" id="bn" required="true"/>
             Author  <apex:inputtext value="{!Log.Author__c}" id="BA"/>
             Price   <apex:inputtext value="{!log.Price__c}" id="BP"/>
       </apex:panelGrid>
   
    </apex:pageBlockSection>
  </apex:pageBlock>
  </apex:form>
</apex:page>

=================Controller==========================
public with sharing class AutoSave {
 
  public Autosave(){
    log=new book__c();
    
  }
  public book__c log{get;set;}
  public void ASMethod(){
   // insert log;
    log.clear();
    
  }
}

Saturday, March 8, 2014

Insert Record Into objectA and same Record insert into ObjectB there is no relation between two sobjects..(update)

trigger InsertingsameRecordintoObjectB on ObjectA__c (after insert,after update) {

 ObjectB__c objB= new ObjectB__c();
 ObjectA__c b1;
 if(Trigger.IsInsert){
    objectA__c objA=Trigger.new[0];
    objB.name=objA.name;
    objB.email__c=ObjA.email__c;
    ObjB.number__c=ObjA.Number__c;
    objB.phone__c=objA.phone__c;
    objB.lastname__c=objA.lastname__c;
    insert objb;
 }
 if(trigger.Isupdate){
   if(trigger.old!= trigger.new){
        b1=trigger.new[0];
      
        system.debug('@@@@@@@@@@@@@@@@@@@@@@@@@@@@'+b1.name);
         objB=[select id, name,email__c,number__c,phone__c,lastname__c from objectB__c where name=:b1.name];
        system.debug('***********************************************'+objB.name);
        objB.name=b1.name;
        objB.email__c=b1.email__c;
        ObjB.number__c=b1.Number__c;
        objB.phone__c=b1.phone__c;
        objB.lastname__c=b1.lastname__c;
        update objB;
    }
 }
 if(trigger.IsDelete){
   for(objectA__c d:Trigger.old){
        objB=[select id, name,email__c,number__c,phone__c,lastname__c from objectB__c where name=:d.name];
        delete objB;
   }
 }
}

Can"t change cost of filed less than previous value

// cant decrese the cost not less than previous value
trigger Trg1 on Empl__c (before update) {
  
    if(trigger.isupdate){
        for(Empl__c Emp1:trigger.new){
            for(Empl__c Emp2:trigger.old){
                if(Emp1.cost__c<Emp2.cost__c){
                    Emp1.adderror('cant');
                } 
            } 
        }  
    }  

}

Max Cost Records is can't Delete by using Triggers....

trigger trigger4 on Empl__c (before delete) {
    if(trigger.isBefore){
       if(trigger.isDelete){
           List< Empl__c> emp=[select  Cost__C from  Empl__c all rows];
           for(Empl__C val:emp){
               for(Empl__c val1:trigger.old){
                    if(val.cost__C > val1.cost__C){
                        if(val.cost__c== val1.cost__c){
                          val1.adderror('u cant delere');
                        }
                      
                    }              
               }
              
           }
       }
    }
}

Unable to Delete Records using Trigger......

trigger trdelet on Empl__c (before delete) {
    if(trigger.isdelete){
        for(Empl__c emp:trigger.old){
            if(emp.cost__c>500){
             emp.adderror('you cant delete ');
            }   
        }   
    }  

}

Duplocates Records Not Allowing using Triggers and cant change field name

trigger DuplicatesTask on TStudent__c  (before insert,before update,before delete,
                             after insert,after update,after delete) {
       if(trigger.IsInsert) {
              for(TStudent__c  o:[select name from TStudent__c ]){
                   for(TStudent__c  v:trigger.new){
                         if(v.name==o.name){
                               //v.adderror('noduplications');
                               Trigger.new[0].name.addError('Duplicate names does not allow');
                          }
                    }
                }   
           }  //end of else part
       if(trigger.Isupdate){
             for(TStudent__c o:[select Email_Id__c from TStudent__c]){
               for(TStudent__c mv:trigger.new){
                   if(mv.Email_Id__c!=o.Email_Id__c){
                       mv .Email_Id__c.addError('Email Id cant be changed');//Trigger.new[0]
                   }                 
               }
             } 
           }    
}

Sunday, March 2, 2014

Wrapperclass exmple




==========================vfpage==================
<apex:page controller="Checkbox_Class" Tabstyle="Account">
  <apex:form >
   <apex:pageBlock Title="List of Accounts" >
    <apex:pageBlockButtons >
     <apex:commandButton value="Display the selected Records" action="{!GetSelected}" rerender="Selected_PBS"/>
       </apex:pageBlockButtons>
         <apex:pageblockSection >
            <apex:pageBlockSection Title="List of Available Accounts" columns="2" >
                <apex:pageblockTable value="{!accounts}" var="a" >
                    <apex:column headerValue="Select" width="60">
                      <apex:inputCheckbox value="{!a.selected}" id="checkedone" />
                    </apex:column>
                    <apex:column headervalue="Account Name" value="{!a.acc.Name}" width="200"/>
                    <apex:column headervalue="Phone" value="{!a.acc.Phone}" width="300"/>
                </apex:pageblocktable>
            </apex:pageBlockSection>
            <apex:pageBlockSection Title="Selected Accounts" id="Selected_PBS">
                <apex:pageblockTable value="{!SelectedAccounts}" var="s"  >
                      <apex:column headervalue="Account Name" value="{!s.Name}" width="30"/>
                      <apex:column headervalue="Phone" value="{!s.Phone}" width="30"/>
                </apex:pageblockTable>
            </apex:pageBlockSection>
        </apex:pageblockSection>
     </apex:pageBlock>
  </apex:form>
</apex:page>
===================controller======================
public class Checkbox_Class
{
List<accountwrapper1> accountList = new List<accountwrapper1>();
    List<Account> selectedAccounts = new List<Account>();
   
       public List<accountwrapper1> getAccounts()
    {
        for(Account a : [select Id, Name, AccountNumber, Phone from Account limit 20])
        accountList.add(new accountwrapper1(a));
        return accountList;
    }

    public PageReference getSelected()
    {
        selectedAccounts.clear();
        for(accountwrapper1 accwrapper : accountList)
        if(accwrapper.selected == true)
        selectedAccounts.add(accwrapper.acc);
        return null;
    }

    public List<Account> GetSelectedAccounts()
    {
        if(selectedAccounts.size()>0)
        return selectedAccounts;
        else
        return null;
    }  

    public class accountwrapper1
    {
        public Account acc{get; set;}
        public Boolean selected {get; set;}
        public accountwrapper1(Account a)
        {
            acc = a;
            selected = false;
        }
    }
}