• uday kumar y
  • NEWBIE
  • 5 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 1
    Replies
<apex:page controller="Dependentpicklist">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection >
   <apex:selectList value="{!selectCountry}" size="1">
        Country<apex:selectOptions value="{!Options}"/>
           <apex:actionSupport event="onchange" action="{!FetchState}" reRender="OutState"/>
</apex:selectList>
   <apex:outputPanel id="OutState">
       <apex:selectList value="{!selectState}" size="1">
            State<apex:selectOptions value="{!StateOptions}"/>
               <apex:actionSupport event="onchange" action="{!FetchDistrict}" reRender="OutDist"/>
</apex:selectList>
   <apex:outputPanel id="OutDist">
       <apex:selectList value="{!selectDistrict}" size="1">
           District<apex:selectOptions value="{!DistrictOptions}"/>
               <apex:actionSupport event="onchange" action="{!FetchVillage}" reRender="OutVig"/>
</apex:selectList>
   <apex:outputPanel id="OutVig">
       <apex:selectList value="{!selectVillage}" size="1">
           Village<apex:selectOptions value="{!VillageOptions}"/>
</apex:selectList>
</apex:outputPanel>
</apex:outputPanel>
</apex:outputPanel>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form> 
</apex:page>



public class Dependentpicklist{
   public string selectCountry{set;get;}
   public string selectState{set;get;}
   public string selectDistrict{set;get;}
   public string selectVillage{set;get;}
   public List<Selectoption> Options{set;get;}
   public List<Selectoption> StateOptions{set;get;}
   public List<selectoption> DistrictOptions{set;get;}
   public List<selectoption> VillageOptions{set;get;}
   
   
   public Dependentpicklist(){
       Options = new List<Selectoption>();
           for(Country__c cou:[select Id,Name from Country__c]){
              Options.add(new Selectoption(cou.Id,cou.Name));
           }
   }
   public void FetchState(){
      StateOptions = new List<Selectoption>();
          for(State__c st:[select Id,Name from State__c where Country__c =:selectCountry]){
              StateOptions.add(new Selectoption(st.Id,st.Name));
          } 
   }
   public void FetchDistrict(){
       DistrictOptions = new List<Selectoption>();
           for(District__c dis:[select Id,Name from District__c where State__c =:selectState]){
               DistrictOptions.add(new Selectoption(dis.Id,dis.Name));
           }
   }
   public void FetchVillage(){
       VillageOptions = new List<Selectoption>();
           for(Village__c vlg:[select Id,Name from Village__c where District__c =:selectDistrict]){
               VillageOptions.add(new Selectoption(vlg.Id,vlg.Name));
           }
   }
}

if i select country before will be display NONE value .then if you select any country then automatically displays the states,districts,villages 
public class Conaccn{
   public static void Conacc(List<Contact> newval){
   List<Account> acc = [select Id from Account where Id =: newval[0].AccountId];
       if(acc.isEmpty()){
           if(newval[0].AccountId == null){
               Account ac = new Account();
                   ac.Name = newval[0].LastName;
                   ac.Phone = newval[0].Phone;
                   ac.Amount__c = 25;
               insert ac;  
        }
    }
  }
}



If(Contact.AccountId==Null)
Contact LastName and AccountName is same 
Contact.AccountId=AccountId
how to write tigger 
I have four objects 
1.ObjectA
2.ObjectB
3.ObjectC
4.ObjectD
ObjectA is parent ObjectB is child,ObjectB is parent ObjectC is child,ObjectC is parent ObjectD is child 
How to write Apex Class?

 
<apex:page controller="Address">
<apex:form >
<apex:pageBlock >
    <apex:pageBlockSection >
        <apex:inputText value="{!Name}" label="Name"/>
    </apex:pageBlockSection>
    <apex:pageBlockSection title="Temporary Address">
        <apex:inputText value="{!City}" label="City"/>
        <apex:inputText value="{!Address}" label="Address"/>
    </apex:pageBlockSection>
    <apex:pageBlockSection title="Addresscheck">
        <apex:inputCheckbox value="{!Addresscheck}" label="Addresscheck"/>
    </apex:pageBlockSection>
    <apex:pageBlockSection title="Permanent Address">
        <apex:inputText value="{!City1}" label="City1"/>
        <apex:inputText value="{!Address1}" label="Address1"/>
    </apex:pageBlockSection>
    <apex:pageBlockButtons >
        <apex:commandButton value="save" action="{!saverecords}"/>
    </apex:pageBlockButtons>
</apex:pageBlock>
</apex:form> 
</apex:page>

public class Address{
    public string Name{set;get;}
    public string City{set;get;}
    public string Address{set;get;}
    public string City1{set;get;}
    public string Address1{set;get;}
    public boolean Addresscheck{set;get;}
   
    
  
    
    public pageReference saverecords(){
    pageReference pref = null;
    Address__c ad = new Address__c();  
      if(Addresscheck == True){  
        ad.Name = Name;
        ad.City__c = City;
        ad.Address__c = Address;
        ad.City1__c = City;
        ad.Address1__c = Address;   
        }
      else{
        ad.Name = Name;
        ad.City__c = City;
        ad.Address__c = Address;
        ad.City1__c = City1;
        ad.Address1__c = Address1;   
      } 
      insert ad;  
      pref = new pageReference('/'+ad.Id);
      return pref;
    }  
 
}


Click the inputcheckbox automatically hide the Permanent Address pageblocksection?
trigger updatepho on Contact (before update){
List<Contact> con = new List<Contact>();
List<Account> acc = [select Id from Account where Name =: con[0].LastName];
    if(con[0].AccountId == null){
        for(Contact c:con){
            c.AccountId = acc[0].Id;
         con.add(c);   
        }
    }
    update con;
}
My error Description:Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger updatepho caused an unexpected exception, contact your administrator: updatepho: execution of BeforeUpdate caused by: System.ListException: List index out of bounds: 0: Trigger.updatepho: line 3, column 1
trigger updatepho on Contact (after insert){
    List<Account> acc = new List<Account>();
    for(Contact con:trigger.new){
      if(con.AccountId == null){
        Account a = [select Id,Phone,(select Id,Phone from Contacts) from Account where Phone =: con.Phone];
               a.Name = con.LastName;
               a.Phone = con.Phone;
               a.Amount__c = 25;
        acc.add(a);
        }
      
    }
    insert acc;
}
This is my error descripation :Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger updatepho caused an unexpected exception, contact your administrator: updatepho: execution of AfterInsert caused by: System.QueryException: List has no rows for assignment to SObject: Trigger.updatepho: line 5, column 1
I have object Account two custom fields one is Amount it requared field anather one is Date field. if we can update  the Amount and  check the Date field is todate or it can through error messege how is it passible?