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
crazycloudcrazycloud 

Create VF page from Custom Controller

Hi,

I want to create a new Contact creation page in VF from Apex custom Controller. I don't want to hardcode the object name Contact and field names in VF page.

Can anybody help me?

 

 

 

 

 

hisrinuhisrinu

You can try with Describe calls, for more information you can refer APEX language reference

crazycloudcrazycloud

I have tried Describe call to get Contact fields. But the fields will be return in a Map with key as field api name and value as SObject field type. But when i pass the list of this SObject field to VF page i got an error that the field should be bind only with SObject.

 

Please provide some piece of code.

Pradeep_NavatarPradeep_Navatar

Try out the sample code given below to describe call to get contact fields and data type respectively :

 

                                                <apex:page controller="AccountFieldController"> 

                                                                <apex:form >

                                                                                <apex:pageBlock >

                                                                                   <apex:dataList value="{!accountFieldResult}" var="af">

                                                                                                   <apex:outputText >{!af}</apex:outputText>

                                                                                   </apex:dataList>

                                                                                </apex:pageBlock>

                                                                </apex:form>

                                                </apex:page>

                                                /*Controller*/

                                                public class AccountFieldController

                                                {

                                                                public List<String> accountFieldResult {get; set;}

                                                                public AccountFieldController()

                                                                {

                                                                  Map<String, Schema.SObjectField> M = Schema.SObjectType.Contact.fields.getMap();

                                                                  Set<String> fieldnames = M.keySet();  

                                                                  List<String> fieldList = new List<String>(); 

                                                                  fieldList.addAll(fieldNames);

                                                                  accountFieldResult = new List<String>();

                                                                   for(integer i=0; i<fieldList.size(); i++)

                                                                   {

                                                                                accountFieldResult.add(fieldList[i]+':'+m.get(fieldList[i]).getDescribe().getType()); 

                                                                   }

                                                   }

                                                }

 

Hope this helps.

crazycloudcrazycloud

I want to create Contact creation page not detail page. Instead of apex:outputText I want apex:inputField.

I know i can create VF page with apex:outputText & apex:inputText but i need apex:inputField