Thursday 28 April 2016

SOME CONTROLERS And CLASSES



public class aaPage52 {
    public Integer X { get; set; }
    public Integer X2 { get; set; }
   
    public aaPage52() {
        X = 0;
        X2 = 0;
    }
    public PageReference TestX() {
        String strX = ApexPages.currentPage().getParameters().get('X');
        if (strX != null) {
            this.X = Integer.ValueOf(strX);
        }
        return null;
    }
    public PageReference TestX2() {
        return null;
    }
}

//////////////////////////////////
public without sharing class AccountController {
    public Account account{get; set;}
    public AccountController(){
        account = new Account();
    }
   
    public void save(){
        upsert account;
    }
}

//////////////////////////////////////////////////
public without sharing class AccountController3 {
    public Account account{get; set;}
    public AccountController3(){
        account = new Account();
    }
   
    public void save(){
        upsert account;
    }
}
///////////////////////////////////////////////////////////////////
public with sharing class AccountPagination {

    private final Account acct;



    // The constructor passes in the standard controller defined

    // in the markup below

    public AccountPagination(ApexPages.StandardSetController controller) {

        this.acct = (Account)controller.getRecord();

    }  

    

    public ApexPages.StandardSetController accountRecords {

        get {

            if(accountRecords == null) {

                accountRecords = new ApexPages.StandardSetController(

                    Database.getQueryLocator([SELECT Name FROM Account WHERE Id NOT IN

                       (SELECT AccountId FROM Opportunity WHERE IsClosed = true)]));

            }

            return accountRecords;

        }

        private set;

    }

    public List<Account> getAccountPagination() {

         return (List<Account>) accountRecords.getRecords();

    }

}
/////////////////////////////////////////////////
public class arrayexample{
    public integer[] ages{set;get;}
    public Account[] accs{set;get;}
     public Contact[] cons{set;get;}
    public arrayexample(){
        ages=new integer[]{10,20,30};
        Account a1=new Account(Name='krishna',Industry='banking'); 
        Account a2=new Account(Name='sri',Industry='energy');
        accs=new Account[]{a1,a2};
            }
    Public void show()
    {
        cons=new contact[4];
        contact c1=new contact(lastname='krishnayerru',phone='123');
        contact c2=new contact(lastname='krishnayerru2',phone='1234');
        cons[0]=c1;
        cons[1]=c2;
    }
   
    
   
}
////////////////////////////////////

public class AutoComplete{

    public List<Account> getAccounts(){
        return [select id,name from Account limit 25];
    }


}
//////////////////////////////////////
///////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

global class batchAccountInsert implements database.Batchable<sObject> {
    global Database.Querylocator start(Database.BatchableContext bc){

        String query='select Name,Industry from Account Limit 1';
        return database.getQueryLocator(query);
    }
    global void execute(Database.BatchableContext bc , List<Account> scope) {
        List<Account> AccountToInsert = new List<Account>{};
        for(Account a :scope)
        {
        Account newAcc = new Account();
        System.debug('Account Industry[' + a.Industry  + '], Name[' + a.name + ']');
        newAcc.Name=a.Name + ' ' + 'Hellokrish' ;
        newAcc.Industry =a.Industry;
        AccountToInsert.add(newAcc);
        }
        insert AccountToInsert;      
   }
   global void finish(Database.BatchableContext bc) {   
}
}


////////////////////////////////////////////////////////

Changepassword

/**
 * An apex page controller that exposes the change password functionality
 */
public with sharing class ChangePasswordController {
    public String oldPassword {get; set;}
    public String newPassword {get; set;}
    public String verifyNewPassword {get; set;}       
   
    public PageReference changePassword() {
        return Site.changePassword(newPassword, verifyNewPassword, oldpassword);   
    }    
   
     public ChangePasswordController() {}
}

//////////////////////////////
public class Controlleraction{
    public List<SelectOption> Alphabets {get; set;}
    public List<SelectOption> Fruits {get; set;}
  
    public String SelectedAlphabet {get; set;}
  
    /*A Constructor which will build the intial list of Alphabets*/
    public Controlleraction(){
        Alphabets = new List<SelectOption>();
        Fruits    = new List<SelectOption>();
      
         /*This is to add the NONE option for our Picklists*/
        SelectOption option = new SelectOption('--None--', '--None--');
        Alphabets.add(option);
        Fruits.add(option);
      
        option = new SelectOption('A', 'A');
        Alphabets.add(option);
      
        option = new SelectOption('B', 'B');
        Alphabets.add(option);      
    }
  
    /*This Method that will actually build the Fruits list for us. The ActionFunction will be calling this function as and when a User changes an Alphabet from the 1st List.*/
    public void createFruitList(){
        /*Always clear the List when begin so that previous values will be removed.*/
        Fruits.clear();
      
        Fruits.add(new SelectOption('--None--', 'None'));
      
        if(SelectedAlphabet == 'A'){
            Fruits.add(new SelectOption('Apple','Apple'));
            Fruits.add(new SelectOption('Apricot','Apricot'));
        }
        else if(SelectedAlphabet == 'B'){
            Fruits.add(new SelectOption('Banana','Banana'));
            Fruits.add(new SelectOption('Blackberry','Blackberry'));
        }
    }
}
////////////////////////////////////////
public class conVsBad {

  Contact c;
  Account a;
  Account s=getAccountMethod1();


    public Contact getContactMethod1() {

        if (c == null) c = [SELECT Id, Name FROM Contact LIMIT 1];

        return c;

    }
    public Account getAccountMethod1() {

        if (a == null) a = [SELECT Id, Name FROM Account LIMIT 1];

        return a;

    }



    public Account getContactMethod2() {

        return s;

    }

}

////////////////////////////////
public class conVsGood {

    Contact c;



    public Contact getContactMethod1() {

        if(c == null) c = [SELECT Id, Name FROM Contact LIMIT 1];

        return c;

   }



    public Contact getContactMethod2() {

        return getContactMethod1();

    }

}
////////////////////////////////////////////////

Public class example108{
Public  String Name{set;get;}
Public Integer Age{Set;get;}
Public example108() {

Name='Krishna';
Age=27;
}

}
////////////////////////


////////////////////////////////////////////////////////////////////////////////////=========================================

public class exampleCon {

    String uname;



    public String getUsername() {

        return uname;

    }

            

    public PageReference sayHello() {

        uname = UserInfo.getName();

        return null;

    }

            

    public void setState(String n) {

        state = n;

    }

            

    public String getState() {

        return state;

    }

            

    public PageReference methodOne() {

        return null;

    }

            

    private String state = 'no';

}



public class exampleCon2 {

    Integer count = 0;

            

    public PageReference incrementCounter() {

        count++;

        return null;

    }

            

    public Integer getCount() {

        return count;

    }

}


public class ExtOne {

    public ExtOne(ApexPages.StandardController acon) { }



    public String getFoo() {

        return 'foo-One';

    }

}

++++++++++++++++++++
public class ExtTwo {

    public ExtTwo(ApexPages.StandardController acon) { }



    public String getFoo() {

        return 'foo-Two';

    }

}





public class FuntionExample {
    public String result {set;get;}
    public string name  {set;get;}
   
    public string krish  {set;get;}
    public void show(){
        result=' This is a call from :'+name;
    }
    Public void show2(){
    krish='this is show2 method';
    }
   
   

}

public class InputPage1 {
    public String name {set;get;}
    public Integer age {set;get;}
    public PageReference show(){
        PageReference p=new PageReference('/apex/inputpage2?name='+name+'&age='+age);
        return p;
    }
}
++++++++++++++++++++++++++++++

public class InputTextExample {
    public String name {set;get;}
    public String branch{set;get;}
     public Integer Age{set;get;}
    public void show(){
   
        name='My Name :'+name;
        Age=+Age;
    }
}


public with sharing class InterviewFifthClass {
public List<account> lstacc { get; set;}

public pagereference click() {
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'you clicked on Name...'));
return null;
}
public InterviewFifthClass (){
lstacc = [select id, name, BillingState,phone,website from account];
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,
'Select an Account by Clicking its Name.'));
}

}

public class JavaScriptExamadd {

    public List<Product> products{set;get;}

    public Integer rowNo{set;get;}

    public JavaScriptExamadd(){

     products=new List<Product>();

        addProducts();

    }

    public void addProducts(){

        for(Integer i=0;i<=3;i++){

            Product p=new Product();

            p.total=0;

            products.add(p);

        }

    }

    public void addRow(){

        Product p=products.get(rowNo);

        if(rowno+1<products.size())

        products.add(rowno+1,p);

        else

        products.add(p);

    }

    public void removeRow(){

        products.remove(rowNo);

    }

    public class product{

        public string pname {set;get;}

        public Integer quant {set;get;}

        public Decimal price {set;get;}

        public Decimal total {set;get;} 

    }

}


public class javascriptList {

    public List<ProductWrap> products{set;get;}

    public List<ProductWrap> selected {set;get;}

    public Integer rowno{set;get;}

    public List<Integer> nos{Set;get;}

    public javascriptList(){

        products=new List<ProductWrap>();

        addMore();

    }

    public void addMore(){

         for(Integer i=0;i<4;i++){

            ProductWrap pw=new ProductWrap();

            products.add(pw);

        }

    }

    public pageReference submit(){

        selected=new List<Productwrap>();

        for(ProductWrap p:products){

            if(p.flag==true){

                selected.add(p);

            }

        }

        PageReference p=new pageReference('/apex/selectedpage');

        return p;

    }

    public void addRow(){

        ProductWrap p=products.get(rowno);

        if(rowno+1 <products.size()){

            products.add(rowno+1,p);

        }

        else{

            products.add(p);

        }

    }

    public void removeRow(){

        products.remove(rowno);

    }

    public void multipleRows(){

       nos=new List<Integer>();

        for(Integer i=0;i<products.size();i++){

        ProductWrap p =products.get(i);

            if(p.flag==true){

                nos.add(i);

            }

        }

        integer x=0;

        for(Integer n:nos){

            if(x<=0)

            products.remove(n);

            else{

                 products.remove(n);  

                }

        }

    }

    public class ProductWrap{

        public String name {set;get;}

        public Decimal price {set;get;}

        public Integer quant {set;get;}

        public Boolean flag {Set;get;}

        public Decimal total{Set;get;}

       

    }

}



public  class ListExample {
     public List<String> names {set;get;}
     public List<Account> accs {set;get;}
     public List<ProdWrap> products {set;get;}
     public List<ProdWrap> selected {set;get;}
     public ListExample(){
          names=new List<String>{'sam','Ram','Kiran'};
          accs=new List<Account>();
          products=new List<ProdWrap>();
          Account a1=new Account(Name='Wipro',Industry='Technology');
          Account a2=new Account(Name='Satyam',Industry='Energy');
          accs.add(a1);
          accs.add(a2);
          for(Integer i=0;i<4;i++){
              ProdWrap pw=new Prodwrap();
              products.add(pw);
          }
     }
     public void getValues(){
          selected=new List<ProdWrap>();
          for(ProdWrap ps:products){
              if(ps.flag==true){
                   selected.add(ps);
              }
          }
     }
     public class prodWrap{
          public String name {set;get;}
          public Decimal price {set;get;}
          public Decimal quant {set;get;}
          public Boolean flag {Set;get;}
          public ProdWrap(){
              flag=false;
          }
     }
}




Multiplefiles upload controllee


public class MultipleUploadController 
{    
    //Picklist of integer values to hold file count 
    public List<SelectOption> filesCountList {get; set;} 
    //Selected count 
    public String FileCount {get; set;} 
     
    public List<Attachment> allFileList {get; set;} 
     
    public MultipleUploadController(ApexPages.StandardController controller) 
    { 
        //Initialize   
        filesCountList = new List<SelectOption>() ; 
        FileCount = '' ; 
        allFileList = new List<Attachment>() ; 
         
        //Adding values count list - you can change this according to your need 
        for(Integer i = 1 ; i < 11 ; i++) 
            filesCountList.add(new SelectOption(''+i , ''+i)) ; 
    } 
     
    public Pagereference SaveAttachments() 
    { 
        String accId = System.currentPagereference().getParameters().get('id'); 
        if(accId == null || accId == '') 
            ApexPages.addmessage(new ApexPages.message(ApexPages.Severity.ERROR,'No record is associated. Please pass record Id in parameter.')); 
        if(FileCount == null || FileCount == '') 
            ApexPages.addmessage(new ApexPages.message(ApexPages.Severity.ERROR,'Please select how many files you want to upload.')); 
 
        List<Attachment> listToInsert = new List<Attachment>() ; 
         
        //Attachment a = new Attachment(parentId = accid, name=myfile.name, body = myfile.body); 
        for(Attachment a: allFileList) 
        { 
            if(a.name != '' && a.name != '' && a.body != null) 
                listToInsert.add(new Attachment(parentId = accId, name = a.name, body = a.body)) ; 
        } 
         
        //Inserting attachments 
        if(listToInsert.size() > 0) 
        { 
            insert listToInsert ; 
            ApexPages.addmessage(new ApexPages.message(ApexPages.Severity.INFO, listToInsert.size() + ' file(s) are uploaded successfully')); 
            FileCount = '' ; 
        } 
        else 
            ApexPages.addmessage(new ApexPages.message(ApexPages.Severity.ERROR,'Please select at-least one file')); 
             
        return null; 
    } 
     
    public PageReference ChangeCount() 
    { 
        allFileList.clear() ; 
        //Adding multiple attachments instance 
        for(Integer i = 1 ; i <= Integer.valueOf(FileCount) ; i++) 
            allFileList.add(new Attachment()) ; 
        return null ; 
    } 
}




public  class MultiSelectExample {
     public List<String> cities{set;get;}
     public Set<String> nscities{set;get;}
     public set<String> scities{set;get;}
     public List<SelectOption> nsoptions{set;get;}
     public List<SelectOption> soptions{set;get;}
     public List<String> selected{set;get;}
     public List<String> removed{Set;get;}
     public MultiSelectExample(){
          cities=new List<String>{'Hyd','Ban','Che','Pune'};
          nscities=new Set<String>();
          scities=new  Set<String>();
          nscities.addAll(cities);
           nsoptions=new List<SelectOption>();
           soptions=new List<selectOption>();
           selectOption op=new SelectOption('none','-None-');
           soptions.add(op);
           createList();
     }
     public void createList(){
         nsoptions.clear();
          soptions.clear();
           selectOption op=new SelectOption('none','-None-');
           soptions.add(op);
           nsoptions.add(op);
          for(String s1: nscities){
              Selectoption op1=new SelectOption(s1,s1);
              nsoptions.add(op1);
          }
          for(String s2: scities){
              Selectoption op2=new SelectOption(s2,s2);
              soptions.add(op2);
          }
     }
     public void addEle(){
          nscities.removeAll(selected);
          scities.addAll(selected);
          createList();
     }
     public void removeEle(){
          scities.removeAll(removed);
          nscities.addAll(removed);
          createList();
     }  
}

Extension



public class myControllerExtension {



    private final Account acct;

    

    // The extension constructor initializes the private member

    // variable acct by using the getRecord method from the standard

    // controller.

    public myControllerExtension(ApexPages.StandardController stdController) {

        this.acct = (Account)stdController.getRecord();

    }



    public String getGreeting() {

        return 'Hello ' + acct.name + ' (' + acct.id + ')';

    }

}


public class outputPage2 {
    public String empName{Set;get;}
    public String age{set;get;}
    public outputPage2 (){
        empName=ApexPages.currentpage().getParameters().get('name');
        age=ApexPages.currentpage().getParameters().get('age');
    }
}

public class outputPage28 {
    public String empName{set;get;}
    public String age{set;get;}
    public outputPage28(){
        empName=ApexPages.currentpage().getParameters().get('name');
        age=ApexPages.currentpage().getParameters().get('age');
    }
   
  
}

public class ParamBlogController
{
 private ApexPages.StandardController stdCtrl {get; set;}
 
 public List<Contact> conts {get; set;}
 
 public ParamBlogController(ApexPages.StandardController std)
 {
  stdCtrl=std;
  setupContacts();
 }
 
 private void setupContacts()
 {
  conts=[select id, Name, Email, Phone from Contact where AccountId=:stdCtrl.getId()];
 }
}
public class PickExample {
    public List<SelectOption> options {set;get;}
    public String selected {Set;get;}
    public String result {set;get;}
    public PickExample(){
        options=new List<SelectOption>();
        SelectOption op1=new SelectOption('none','-None-');
        SelectOption op2=new SelectOption('TG','Hyd');
        SelectOption op3=new SelectOption('TN','Che');
        SelectOption op4=new SelectOption('KA','Ban');
        options.add(op1);
        options.add(op2);
        options.add(op3);
        options.add(op4);
    }
    public void selectedmethod(){
        result='You Have selected :'+selected;
    }
}
public class repeatCon {



    public String[] getStrings() {

        return new String[]{'ONE','TWO','THREE'};

    }



}
public class sampleapex {
 
   
    List<Account> accs=new List<Account>();
   
    public void show(){
       
   accs =[Select id,Name from Account limit 1];
        system.debug('hai');
       
    }
}

public class sampleclass
{
    public integer a{set;get;}
    public integer b{set;get;}
    public string call{set;get;}
    public sampleclass(){
        a=10;
        b=3;
       call='hai';
    }
 /*   public string call(){
      
        call='This is calling method';
        return call;
    }
*/
}

public class samplesoql2{
     public List<Contact> cons{set;get;}
    Public String Searched{set;get;}
    public Void Submit(){
        cons=[select id,Lastname,Firstname from Contact where name=:Searched];
    }
}

+++++++
public class SampleSoql {
    public List<Account> accs{set;get;}
    Public String Searched{set;get;}
    public Void Submit(){
        accs=[select id,name,industry from account where name=:Searched];
    }
}
public  class SchemaDynamicExample {
     public Map<String,Schema.SobjectType> objMap {Set;get;}
     public Map<String,Schema.SobjectField> fldMap {set;get;}
     public List<String> objList {Set;get;}
     public List<SelectOption> objOptions{set;get;}
     public String objselected{set;get;}
     public List<String> fldList{set;get;}
     public Set<String> nsflds{set;get;}
     public Set<String> sflds{Set;get;}
     public List<SelectOption> nsoptions{set;get;}
     public List<SelectOption> soptions{set;get;}
     public List<String> selected{set;get;}
     public List<String> removed{set;get;}
     public List<Account> accs{set;get;}
     public String query {Set;get;}
     public List<String> pbtflds{Set;get;}
     public SchemaDynamicExample(){
          objList=new List<String>();
          objOptions=new List<SelectOption>();
          fldList=new List<String>();
          nsflds=new Set<String>();
          sflds=new Set<String>();
          nsoptions=new List<SelectOption>();
          soptions=new List<SelectOption>();
          selected=new List<String>();
          removed=new List<String>();
          getObjects();
          SelectOption op=new SelectOption('none','-none-');
          nsoptions.add(op);
          soptions.add(op);
     }
     public void getObjects(){
          objMap=Schema.getGlobalDescribe();
          Set<String> keys=objMap.keySet();
          objList.addAll(keys);
          objList.sort();
          SelectOption op=new SelectOption('none','-None-');
          objoptions.add(op);
          for(String s:objList){
              selectOption op1=new SelectOption(s,s);
              objOptions.add(op1);
          }
     }
     public void getResults(){
          query='select id';
          for(string s:sflds){
              if(s!='id'){
                   query=query+','+s;
              }
          }
          query=query+' from Account';
          accs=Database.query(query);
          pbtflds=new List<String>();
          pbtflds.addAll(sflds);
     }
     public void getFields(){
          Schema.DescribeSobjectResult result=objMap.get(objSelected).getDescribe();
          fldmap=result.fields.getMap();
          Set<String> keys=fldmap.keySet();
          fldList.addAll(keys);
          fldList.sort();
          nsflds.addAll(fldList);
          multiselect();
     }
    public void  multiselect(){
          nsoptions.clear();
          soptions.clear();
        
          List<String> slist=new List<String>();
          slist.addAll(sflds);
          slist.sort();
          List<String> nslist=new List<String>();
          nslist.addAll(nsflds);
          nslist.sort();
          for(String s1:nslist){
              SelectOption op1=new SelectOption(s1,s1);
              nsoptions.add(op1);
          }
          for(String s2:slist){
              SelectOption op2=new SelectOption(s2,s2);
              soptions.add(op2);
          }  
   }
   public void addEle(){
          nsflds.removeAll(Selected);
          sflds.addAll(selected);
          multiselect();
   }
   public void removeEle(){
          sflds.removeAll(removed);
          nsflds.addAll(removed);
          multiSelect();
   }
}

public  class SchemaExample{
     public Map<String,Schema.SobjectType> objects {set;get;}
     public List<SelectOption> options {set;get;}
     public List<String> objNames{set;get;}
     public String selected {set;get;}
     public String describe {Set;get;}
     public SchemaExample(){
          objects=Schema.getGlobalDescribe();
          options=new List<selectOption>();
          objNames=new List<String>();
          Set<String> keys=objects.keySet();
          objNames.addAll(keys);
          objNames.sort();
          for(String s:objNames){
              SelectOption op=new SelectOption(s,s);
              options.add(op);
          }
   
     }
     public void getDetails(){
          Schema.DescribeSobjectResult result=objects.get(selected).getDescribe();
          describe=''+result;
     }

}

public class selectcomponent{

Public String Grade{set;get;}
Public String gender{set;get;}
Public selectcomponent(){

}

Public String Save(){


string Save='Hello';
return save;

}



Pagenation



public  class SOQLPagination {

public List<Account> accs{set;get;}

public  Integer size {set;get;}

public  Integer  flimit{set;get;}

public Integer acount{set;get;}

public SOQLPagination(){

size=5;

flimit=0;

    acount=[select count() from Account];

accs=[select id,name,industry from Account limit :size offset :flimit];

}

public void next(){

accs=[select id,name,industry from Account limit :size offset :flimit];

}

public void previous(){

flimit=flimit+5;

accs=[select id,name,industry from Account limit :size offset :flimit];



if(flimit>0)

flimit=flimit-5;
}
}

public class WithoutPageReference{
Public Opportunity opp;
public WithoutPageReference(){
/*opp= [select id,Name,DeliveryInstallationStatus__c,TrackingNumber__c,CloseDate
from Opportunity where id=:ApexPages.currentPage().getParameters().get('Id')];
*/
opp= [select id,Name,DeliveryInstallationStatus__c,TrackingNumber__c,CloseDate
from Opportunity];

}
public Opportunity getOpportunity () {
return opp;
}
public PageReference SaveMethod() {
update opp;
return null;
}
}
Public Class yerru1{
Public List<Registration__c> Regs{set;get;}
Public List<Registration__c> regsall(){

Regs= [select ID,First_Name__c,Last_Name__c,Mobile__c,Status__c From Registration__c];
Return Regs;

}

}
Public Class yerru8{
Public List<Registration__c> Regs{set;get;}
Public void regsall(){

Regs= [select ID,First_Name__c,Last_Name__c,Mobile__c,Status__c From Registration__c];
//Return Regs;

}

}




No comments:

Post a Comment