+ Start a Discussion
STest123STest123 

Dynamic Field Create

Hi anyone guess Can i create a dynamic field in apex at run time . if yes then how it's Possible?

Best Answer chosen by Admin (Salesforce Developers) 
Navatar_DbSupNavatar_DbSup

Hi,

Try the below code snippet as reference:

 

--------------- Vf page------------- <apex:page controller="examples15" >

<apex:form >

 

<table>

<tr>

<td><apex:dynamicComponent componentValue="{!outtext}" />

</td>

<td><apex:dynamicComponent componentValue="{!cmdbutton}"/><Br/>

</td>

</tr>

<tr>

<td><apex:dynamicComponent componentValue="{!intext}"/>

</td>

<td><apex:inputText disabled="true" />

</td>

</tr>

</table>

  </apex:form>

</apex:page>

 

---------------- Apex Controller ----------------------

 

public class examples15

{

 

    public Component.Apex.OutputText getOuttext()

    {

   

    Component.Apex.OutputText outText = new Component.Apex.OutputText();

    outText.value = 'Some dynamic output text.';

   

    return outText;

    }

   

    public Component.Apex.InputText getintext()

    {

   

    Component.Apex.InputText inText = new Component.Apex.InputText();

      inText.value = 'Some dynamic output text.';

      inText.size = 50;

      inText.style='width:200px';

      inText.style='height:50px';

     inText.disabled=false;

   

    return inText;

    }

   

    public Component.Apex.CommandButton getcmdbutton()

     {

   

         Component.Apex.CommandButton cmdbutton = new Component.Apex.CommandButton();

         cmdbutton.value = 'Click';

         return cmdbutton;

     }

}

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

 

All Answers

Navatar_DbSupNavatar_DbSup

Hi,

Try the below code snippet as reference:

 

--------------- Vf page------------- <apex:page controller="examples15" >

<apex:form >

 

<table>

<tr>

<td><apex:dynamicComponent componentValue="{!outtext}" />

</td>

<td><apex:dynamicComponent componentValue="{!cmdbutton}"/><Br/>

</td>

</tr>

<tr>

<td><apex:dynamicComponent componentValue="{!intext}"/>

</td>

<td><apex:inputText disabled="true" />

</td>

</tr>

</table>

  </apex:form>

</apex:page>

 

---------------- Apex Controller ----------------------

 

public class examples15

{

 

    public Component.Apex.OutputText getOuttext()

    {

   

    Component.Apex.OutputText outText = new Component.Apex.OutputText();

    outText.value = 'Some dynamic output text.';

   

    return outText;

    }

   

    public Component.Apex.InputText getintext()

    {

   

    Component.Apex.InputText inText = new Component.Apex.InputText();

      inText.value = 'Some dynamic output text.';

      inText.size = 50;

      inText.style='width:200px';

      inText.style='height:50px';

     inText.disabled=false;

   

    return inText;

    }

   

    public Component.Apex.CommandButton getcmdbutton()

     {

   

         Component.Apex.CommandButton cmdbutton = new Component.Apex.CommandButton();

         cmdbutton.value = 'Click';

         return cmdbutton;

     }

}

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

 

This was selected as the best answer
STest123STest123

Good Answers thanks   i think it 's new concepts.