Hi,
Visulaforce Page
So in above example I used an sObject instance and showed 5 fields only of that Object type. In above example I used Account object you can decide any object pass the name from any parameter or get as input from User using Picklist.
Related Post : http://forceschool.blogspot.com/2011/06/dynamic-binding-using-field-sets.html
Regards
In earlier post we talked about dynamic binding with field set in this object name was static and fields were coming dynamically from Field Sets.Now we will talk about other way when both Object and Fields are dynamic.
Now we will take examples where object name and fields both are dynamic and fields are not coming from Field Sets either.
Controller Class
public class DynamicBinding { public sObject sObjectToBind {get;set;} public List<String> listObjectFields {get;set;} public DynamicBinding() { listObjectFields = new List<String>(); Map<String , Schema.SObjectType> globalDescription = Schema.getGlobalDescribe(); //In this example I have hard coded the object name Schema.sObjectType sObjType = globalDescription.get('Account'); sObjectToBind = sObjType.newSObject(); Schema.DescribeSObjectResult r1 = sObjType.getDescribe(); Map<String , Schema.SObjectField> mapFieldList = r1.fields.getMap(); Integer i = 0; for(Schema.SObjectField field : mapFieldList.values()) { Schema.DescribeFieldResult fieldResult = field.getDescribe(); if(fieldResult.isAccessible() && fieldResult.isUpdateable()) { listObjectFields.add(fieldResult.getName()); } if(i == 5) break; i++; } } }
Visulaforce Page
<apex:page controller="DynamicBinding"> <apex:form> <apex:pageBlock title="Without Field Set Use"> <apex:pageBlockSection title="Dynamic Object"> <apex:repeat value="{!listObjectFields}" var="fieldAPIName"> <apex:inputField value="{!sObjectToBind[fieldAPIName]}"/> </apex:repeat> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
So in above example I used an sObject instance and showed 5 fields only of that Object type. In above example I used Account object you can decide any object pass the name from any parameter or get as input from User using Picklist.
Related Post : http://forceschool.blogspot.com/2011/06/dynamic-binding-using-field-sets.html
Regards
thanks Sir it is really a worthy approach for getting fields of an Object(even it is dynamic) without using Field Set.
ReplyDeletemax. how many fields of that object we can show here?
@Sandeep
ReplyDeleteAny number of fields you can bind I used 5 just for example.
Yes Its really Good Example.
ReplyDeleteCould you please Implement Save() for this page.
Thank you very much, it's just what I was looking for.
ReplyDeleteHi Shashikant Sharma,
ReplyDeleteThis is very help ful to my task.Could you please Implement Save() for this page.
Hi Shashikant Sharma,,
ReplyDeleteplease help me how to give save() functionality of above without using fieldset related dynamic object .
please help me................
Hi sreekanth,
ReplyDeleteI want to save functionality of without using fieldset functionality
help me.....
Hi sreekanth,
ReplyDeleteUsing above code i displayed all fields dynamically without using fieldset in an visualforce page, On my page More than one multiselectpicklists are there.I want to how to display all these multiselectpicklists values as checkboxes Dynamically?
help me...
This comment has been removed by the author.
ReplyDeleteHi.
ReplyDeleteIm trying to implement a similar solution to input the mandatory fields of an sobject. However, the values that I enter in the form via inputField is not getting set to the Sobject.
campaignToInsert is an Sobject initialised as campaignToInsert = Schema.getGlobalDescribe().get('Campaign').newSObject();
https://saglamproxy.com
ReplyDeletemetin2 proxy
proxy satın al
knight online proxy
mobil proxy satın al
EVİZTA