SHARE
TWEET

Untitled

a guest Jun 19th, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!-- call custom controller -->
  2. <apex:page controller="DVUController">
  3.     <apex:form id="form">
  4.  
  5.         <apex:pageBlock title="Welcome {!$User.FirstName} to the Data Validation Utilities Page">
  6.  
  7.             <apex:pageBlockSection columns="5">
  8.  
  9.                 <apex:pageblocksection title="Select Object" columns="1">
  10.                     <apex:selectList value="{!selectedObject}" size="1">
  11.                         <apex:selectOptions value="{!objectOptions}" />
  12.                         <apex:actionSupport reRender="form" event="onchange" />
  13.                     </apex:selectList>
  14.                 </apex:pageblocksection>
  15.  
  16.                 <apex:pageblocksection title="Picklist Fields" columns="1">
  17.                     <apex:pageblocktable value="{!picklistfields}" var="results">
  18.                         <apex:column value="{!results}"></apex:column>
  19.                     </apex:pageblocktable>
  20.                 </apex:pageblocksection>
  21.  
  22.                 <apex:pageblocksection title="Select Picklist Field" columns="1">
  23.                 <apex:selectList value="{!selectedPicklistField}" size="1">
  24.                         <apex:selectOptions value="{!pickListFieldOptions}" />
  25.                     </apex:selectList>
  26.                 </apex:pageblocksection>
  27.  
  28.                 <apex:pageblocksection title="Picklist Values" columns="1">
  29.                 <apex:pageblocktable title="Picklist Field Values" value="{!picklistvalues}" var="results">
  30.                         <apex:column title="Picklist Field Values" value="{!results}"></apex:column>
  31.                 </apex:pageblocktable>
  32.                 </apex:pageblocksection>
  33.  
  34.             </apex:pageblocksection>
  35.         </apex:pageBlock>
  36.     </apex:form>
  37. </apex:page>
  38.      
  39. public class DVUController {
  40.  
  41. public String selectedObject { get; set; }
  42. public String selectedField { get; set; }
  43. public String selectedPicklistField { get; set; }
  44. public List<String> picklistFields=new List<String>();
  45. public List<String> picklistValues=new List<String>();
  46.  
  47.  
  48. //generate list of Objects from the Org using Dynamic Apex
  49.  
  50. public SelectOption[] getObjectOptions() {
  51.     SelectOption[] results = new SelectOption[] { new SelectOption('','-- none --') };
  52.     for(SObjectType sobjectType: Schema.getGlobalDescribe().values()) {
  53.         DescribeSObjectResult dsrao = sobjectType.getDescribe();
  54.         results.add(new SelectOption(dsrao.getName(), dsrao.getLabel()));
  55.         results.sort();
  56.     }
  57.     return results;    
  58. }
  59.  
  60.  //generate list of names of PicklistFields and MultiPicklistFields from the Object
  61.  
  62.  public List<String> getPicklistFields(){
  63.     if(selectedObject != NULL){
  64.         //picklistfields = new List<String>();
  65.         Schema.DescribeSObjectResult dsr = Schema.getGlobalDescribe().get(selectedObject).getDescribe();
  66.         Map<String,Schema.SObjectField> fieldMap = dsr.fields.getMap();
  67.         for(String fieldName : fieldMap.keySet()) {
  68.             Schema.SObjectField field = fieldMap.get(fieldName);
  69.             Schema.DescribeFieldResult dfr = field.getDescribe();
  70.                if( dfr.getType()==Schema.DisplayType.Picklist || dfr.getType()==Schema.DisplayType.MultiPicklist ) {
  71.                   picklistfields.add(fieldName);
  72.                }  
  73.             system.debug('==>picklistfields==>'+picklistfields);
  74.         }
  75.         return picklistfields;          
  76.     }
  77.     return NULL;
  78. }
  79.  
  80.  //generate list of PicklistFields from the Object as a dropdown
  81.  
  82. public SelectOption[] getPicklistFieldOptions() {
  83.     SelectOption[] results = new SelectOption[] { new SelectOption('','-- none --') };
  84.     if(selectedObject != null) {
  85.         for(SObjectField sObjectField: Schema.getGlobalDescribe().get(selectedObject).getDescribe().fields.getMap().values()) {
  86.             DescribeFieldResult dfr = sObjectField.getDescribe();
  87.             if( dfr.getType()==Schema.DisplayType.Picklist || dfr.getType()==Schema.DisplayType.MultiPicklist ) {
  88.             results.add(new SelectOption(dfr.getName(), dfr.getLabel()));
  89.             results.sort();
  90.         }
  91.     }
  92.     }
  93.     return results;
  94. }
  95.  
  96. //generate list of Picklistvalues from the Picklist selected
  97.  
  98.  public List<String> getPicklistValues(){
  99.          if(selectedPicklistField != NULL && selectedObject != NULL){
  100.          //pickListValues = new List<String>();
  101.          Schema.DescribeSObjectResult dsr = Schema.getGlobalDescribe().get(selectedObject).getDescribe();
  102.          Map<String,Schema.SObjectField> fieldMap = dsr.fields.getMap();
  103.             for(String fieldName : fieldMap.keySet()) {
  104.             Schema.SObjectField field = fieldMap.get(fieldName);
  105.             Schema.DescribeFieldResult dfr = field.getDescribe();
  106.             List<Schema.PickListEntry> picks = dfr.getPicklistValues();
  107.             for(Schema.picklistentry v:picks){
  108.             pickListValues.add(v.getValue());
  109.              system.debug('==>pickListValues==>'+pickListValues);
  110.      }
  111.      return picklistValues;
  112.  }
  113.  
  114.     }
  115.     return picklistValues;
  116.     }
  117.  
  118.   }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top