You need to sign in to do that
Don't have an account?
crazycloud
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?
You can try with Describe calls, for more information you can refer APEX language reference
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.
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.
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