+ Start a Discussion
anu123anu123 

creating picklist field name and values under particular object.

Hi all,

     i create the vf page for displaying all objects in picklist form.next i want to select one object and palce two fields like name, value.(name is the picklistfield name and values are the picklist  value created under the selected object).any one can u please help me.

 

thanks in advance.

anu

Chamil MadusankaChamil Madusanka

Hi Anu,

 

This is combined with your previous post. After getting the object you need to get the fields of selected object. Am I correct with your requirment?

 

If correct, you can get help from following code. There You can type the object name and get fields.

 

<apex:page controller="GeneratorController">
  <apex:form >
  
  <apex:pageBlock >
      <apex:pageblockButtons >
          <apex:commandButton value="Generate Code" action="{!generateCode}"/>
      </apex:pageblockButtons>
      
      <apex:pageblockSection columns="1">
          <apex:pageBlockSectionItem >
              <apex:outputLabel value="Object Name"></apex:outputLabel>
              <apex:inputText value="{!objectName}"/>
          </apex:pageBlockSectionItem>
      </apex:pageblockSection>
       
       <apex:pageblockSection title="Fields">
           <apex:pageBlockSectionItem >
              <apex:commandButton value="Display Fields" action="{!displayFields}"/>
          </apex:pageBlockSectionItem>
       </apex:pageBlockSection>
       
       <apex:pageblockSection title="Generated Code">
           <apex:pageBlockSectionItem >
              <apex:outputlabel value="{!generatedCode}"></apex:outputlabel>
             <apex:outputLabel value="{!msg}"></apex:outputLabel>
          </apex:pageBlockSectionItem>
          
          
       </apex:pageBlockSection>
       <apex:dataTable value="{!queryResult}" var="ff">
       <apex:column >
           
             <apex:inputCheckbox id="field"/>
             <apex:outputLabel value="{!ff}"></apex:outputLabel>
          <!--   <apex:outputText value="{!ff}"/>-->
           </apex:column>
       </apex:dataTable>
  </apex:pageBlock>
    
  </apex:form>
</apex:page>

 

public class GeneratorController {

    public String msg { get; set; }
    public String objectName{ get {return objectName;} set{objectName= value ;} }
    public String generatedCode{get;set;}
    public List<String> queryResult { get ; set ;}
    Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();
    public Schema.SObjectField ss {get;set;}
    
   // Map<String, Schema.SObjectField> M =new  Map<String, Schema.SObjectField>();
    
    public PageReference displayFields(){
        String objName = objectName;
        queryResult=new List<String>();
        
        
       gd = Schema.getGlobalDescribe();
       System.Debug('GDGDGD ::: '+gd);
        SObjectType objToken = Schema.getGlobalDescribe().get(objName);
        
        if(objToken==null){
            msg='OBJECT API NAME IS INVALID. CHECK THE OBJECT API NAME';
        }else{
         msg='';
        DescribeSObjectResult objDef = objToken.getDescribe();
        Map<String, SObjectField> fields = objDef.fields.getMap(); 
        
        Set<String> fieldSet = fields.keySet();
        for(String s:fieldSet)
        {
            SObjectField fieldToken = fields.get(s);
            DescribeFieldResult selectedField = fieldToken.getDescribe();
            System.debug('FIELD ::: '+selectedField.getName());
            queryResult.add(selectedField.getName());
        }
        
        }
        
       //String queryString='SELECT id FROM '+objName+' LIMIT 1';
              
       // Schema.SObjectType obj= gd.get(objName);
       
      // if(obj==null){
      //  msg='OBJECT API NAME IS INVALID. CHECK THE OBJECT API NAME';
       
     //  }else{
       //msg=objName;
      // M=Schema.SObjectType.Employee__c.fields.getMap();
      // ss =M.get('name');
     //  System.Debug('FIELD ::::::::'+ ss);
       
          // queryResult = Database.query(queryString);
       //}
    
        return null;
    }
    
    public PageReference generateCode(){
    
        return null;
    }

}

 I hope this will be helped you to resolve your problem.

 

If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.

 

Chamil's Blog

anu123anu123

Hi chamli,

 Thank u for ur reply.But  my requirement is create the pick list field name and its values under the selected object through vf page.for example i select the object like account and place two field in vf page .one is for pick list field name and another one is for entering picklist values.after click on save the picklist field is created under the account objece.Please send send me the sample code.

 

Thanks  in advance

anu

 

Chamil MadusankaChamil Madusanka

HI,

 

That mean ,you want to create picklist field with values in apex code. Isn't it?

anu123anu123

Hi ,

 

  Thank u so much for ur reply.

    Ya  Exactly same what u said in previous post.i want to enter the  picklist field name and its values in vf page under selected object. that field will be created under that selected object.please send me the sample code.

 

Thanks in advance.

anu