You need to sign in to do that
Don't have an account?
Manoj Goswami 5
How to list all required fields of a selected object ?
Apex:
Thanks in advance...
<apex:page controller="allObjectListClass"> <apex:pageBlock> <apex:form id = "myForm"> <apex:pageBlockSection> <apex:selectList id="objList" value="{!selectedObj}" size="1"> <apex:selectOptions value="{!objName}"/> <apex:actionSupport event="onchange" reRender="myForm"/> </apex:selectList> </apex:pageBlockSection> <apex:pageBlockSection> <apex:pageblockTable value="{!fieldName}" var="f"> <apex:column value="{!f}"/> </apex:pageblockTable> </apex:pageBlockSection> </apex:form> </apex:pageBlock> </apex:page>Controller :
public class allObjectListClass { public String selectedObj {get;set;} public static List<selectOption> getObjName(){ List<selectOption> options = new List<selectOption>(); for ( Schema.SObjectType o : Schema.getGlobalDescribe().values() ) { Schema.DescribeSObjectResult objResult = o.getDescribe(); system.debug( 'Sobject API Name: ' + objResult.getName() +' Sobject Label Name: ' + objResult.getLabel()); options.add(new SelectOption(objResult.getName(),objResult.getLabel())); } return options; } public static List<String> getFieldName(){ List<String> reqFields = new List<String>(); /* Required Code */ return reqFields; } }I am getting a hard time dealing with schema methods, i have gone through the Salesforce documentation though.
Thanks in advance...
You can execute below code..you will get all the required field from the object.
I made selectedObj as a static variable so that we can access in your static method.
Please mark this as a best answer if you this class helps you to solve your problem
All Answers
Please check sample code here :
Hope this helps you.
Please let me know in case of any other assistance.
Thanks
Varaprasad
You can execute below code..you will get all the required field from the object.
I made selectedObj as a static variable so that we can access in your static method.
Please mark this as a best answer if you this class helps you to solve your problem
Thanks , worked like a charm.
What if i want to display same list of Sobject in Alphabetically order in VF page,..
How it can be done
Regards
Pranav Shah