function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sree SalesforceSree Salesforce 

Vf page selecting batch class .That class name is passing as a string. one method will call Database.ExecuteBatch using the string as the name of the class . Here i want to pass one parameter from apex class to batch class.which i was selected in VF.

Here how shall I send parameter from apex class to batch class In this scenario. I have highligted code.where i want to send as a param.
public class DynamicBatchClass {
    public string selectedclass{get;set;}
    public string classname{get;set;}
    public string inputquery{get;set;}
    public DynamicBatchClass(){
       
    }
    public list<selectoption> getclassnameslist ()
    {
        map<string,sobject> instanceMap=new map<string,sobject>();
        list<selectoption> options=new list<selectoption>();
       system.debug('---->>>>-');
         list<ApexClass> ClassNames=new list<ApexClass>();
        options.add(new selectoption('--None--','--None--'));
        ClassNames=[select Id,name,body from ApexClass];
        for(ApexClass ac:ClassNames)
        { 
           if(ac.body.contains('batch')){
           system.debug('-----'+ac.name);
           options.add(new selectoption(ac.Id,ac.name));
           instanceMap.put(ac.name, ac);
           system.debug('--instanceMap--'+instanceMap);
      }
     }
     
   return options;
 }
 
 public void run(){
     system.debug('--selectedclasses--'+selectedclass);
     system.debug('--query-->'+inputquery);
    Type classType = Type.forName(selectedclass);
    Database.Batchable<sobject> instance = (Database.Batchable<sobject>)classType.newInstance();
    Database.executeBatch((Database.Batchable<sObject>)instance, 100);    

  }
}

Any one help me to pass the classname

VF :- <apex:page controller="DynamicBatchClass" showHeader="false" standardStylesheets="false" sidebar="false" docType="html-5.0" applyBodyTag="False" applyHtmlTag="False">    
   <html xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" lang="en" >
    <apex:stylesheet value="{!URLFOR($Resource.SLDS24, 'assets/styles/salesforce-lightning-design-system-vf.min.css')}" />
 <apex:form>
     
      <div class="slds" role="banner">
      <div class="slds-grid">
             <div class="slds-form-element">
  <label class="slds-form-element__label" for="text-input-01">Input Label</label>
  <div class="slds-form-element__control">
    <input type="text" id="text-input-01" class="slds-input" placeholder="Placeholder Text" />
  </div>
</div>
              <div class="slds-text-heading--large">Select Batch Class</div>
             <apex:selectList value="{!selectedclasses}" multiselect="false" size="1" label="Select Batch Class">
                 <apex:selectOptions value="{!classnameslist}"></apex:selectOptions>
             </apex:selectList>
       </div>   
    </div>
    <apex:pageblock >
     
         <apex:pageBlockSection >
             <apex:inputTextArea label="Query"></apex:inputTextArea>
        </apex:pageBlockSection>
     </apex:pageblock>
 </apex:form>
  </html>
</apex:page>