Skip to main content
added 2239 characters in body
Source Link
Ankuli
  • 700
  • 2
  • 13
  • 29

You can do it by maintaining the values atPlease refer this code for your class side

Create new varaible; private List<SelectOption> options;

initialize it in constructor at 1st line; options = new List<SelectOption>()

then. from this methodI have created a new String variable getName remove this line List<SelectOption> options = new List<SelectOption>();strGeographix and you are done with your solution.

earlier what was happening, when ever you was changing thewhich will store geograpic values of Country,and put in your optionserrorMap List was re-initializingon every timecall.

    public class RfpControllerExtension2 {

public string model{get;set;}
public List<String> SelectedDept{get;set;}
public List<Geography__c> results{get;set;}
public List<SelectOption> AllDept{get;set;}
public List<SelectOption> AllName{get;set;}
public List<String> SelectedName{get;set;}
public String discountScheduleID { get; set; }

private String strGeographix = '';

public RfpControllerExtension2 (){
    AllDept= new List<SelectOption>();
    AllDept= getDept();
    AllName= new List<SelectOption>();
    AllName= getName();

}

public void FindAllName()
    {
        system.debug('@@@@@@ Entered');
        AllName= new List<SelectOption>();
        AllName= getName();
    }  

public List<SelectOption> getDept()
    {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('Select','--Select--'));
        Schema.DescribeFieldResult departfield =  Geography__c.Country__c.getDescribe();
        List<Schema.PicklistEntry> picklist = departfield.getPicklistValues();
        for( Schema.PicklistEntry f : picklist){      
        options.add(new SelectOption(f.getLabel(), f.getValue()));
        }    
        return options;

     }

   public List<SelectOption> getName()
    {
        List<SelectOption> options = new List<SelectOption>();
        Set<String> sProj = new Set<String>();
        
        if(discountScheduleID != null )
            {
               for(Geography__c Proj  :[select Id, Canonical_Name__c, Type__c from Geography__c where status__c = 'active' AND Country__c =: discountScheduleID order by Canonical_Name__c] )
               {
                    options.add(new SelectOption(Proj.ID,Proj.Canonical_Name__c));
                    strGeographix += Proj.Canonical_Name__c + ', ';
               }
            }
            errorMap.put('selectedGeographies',Proj.Canonical_Name__c);

        return options;

     }

     public Map<String, String> errorMap {
        get {
            if (errorMap == null || errorMap.size() == 0) {
                errorMap = new Map<String, String> {
                    'selectedGeographies' => '',
                    'flightDates' => '',
                    'agency' => '',
                    'agencyContact' => ''
                };
            }
            return errorMap;
        }
        private set;
    }

}

You can do it by maintaining the values at class side

Create new varaible; private List<SelectOption> options;

initialize it in constructor at 1st line; options = new List<SelectOption>()

then from this method getName remove this line List<SelectOption> options = new List<SelectOption>(); and you are done with your solution.

earlier what was happening, when ever you was changing the values of Country, your options List was re-initializing every time.

Please refer this code for your class. I have created a new String variable strGeographix which will store geograpic values and put in your errorMap on every call.

    public class RfpControllerExtension2 {

public string model{get;set;}
public List<String> SelectedDept{get;set;}
public List<Geography__c> results{get;set;}
public List<SelectOption> AllDept{get;set;}
public List<SelectOption> AllName{get;set;}
public List<String> SelectedName{get;set;}
public String discountScheduleID { get; set; }

private String strGeographix = '';

public RfpControllerExtension2 (){
    AllDept= new List<SelectOption>();
    AllDept= getDept();
    AllName= new List<SelectOption>();
    AllName= getName();

}

public void FindAllName()
    {
        system.debug('@@@@@@ Entered');
        AllName= new List<SelectOption>();
        AllName= getName();
    }  

public List<SelectOption> getDept()
    {
        List<SelectOption> options = new List<SelectOption>();
        options.add(new SelectOption('Select','--Select--'));
        Schema.DescribeFieldResult departfield =  Geography__c.Country__c.getDescribe();
        List<Schema.PicklistEntry> picklist = departfield.getPicklistValues();
        for( Schema.PicklistEntry f : picklist){      
        options.add(new SelectOption(f.getLabel(), f.getValue()));
        }    
        return options;

     }

   public List<SelectOption> getName()
    {
        List<SelectOption> options = new List<SelectOption>();
        Set<String> sProj = new Set<String>();
        
        if(discountScheduleID != null )
            {
               for(Geography__c Proj  :[select Id, Canonical_Name__c, Type__c from Geography__c where status__c = 'active' AND Country__c =: discountScheduleID order by Canonical_Name__c] )
               {
                    options.add(new SelectOption(Proj.ID,Proj.Canonical_Name__c));
                    strGeographix += Proj.Canonical_Name__c + ', ';
               }
            }
            errorMap.put('selectedGeographies',Proj.Canonical_Name__c);

        return options;

     }

     public Map<String, String> errorMap {
        get {
            if (errorMap == null || errorMap.size() == 0) {
                errorMap = new Map<String, String> {
                    'selectedGeographies' => '',
                    'flightDates' => '',
                    'agency' => '',
                    'agencyContact' => ''
                };
            }
            return errorMap;
        }
        private set;
    }

}
Source Link
Ankuli
  • 700
  • 2
  • 13
  • 29

You can do it by maintaining the values at class side

Create new varaible; private List<SelectOption> options;

initialize it in constructor at 1st line; options = new List<SelectOption>()

then from this method getName remove this line List<SelectOption> options = new List<SelectOption>(); and you are done with your solution.

earlier what was happening, when ever you was changing the values of Country, your options List was re-initializing every time.