Return to Snippet

Revision: 29366
at July 28, 2010 04:24 by d3developer


Initial Code
    public void getLabelsAndWidthsfromFields(List<String> fieldNames, String objectName)
    { 
		  labels = new List<String>();      	       
		  widths = new List<String>();    	
 
		  try {
				Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();
				SObjectType sot = gd.get(objectName);
			    Map<String, SObjectField> fields = sot.getDescribe().fields.getMap();
			    List<SObjectField> fieldtokens = fields.values();
			    for(String fn : fieldNames)
			    {
			    	SObjectField field = fields.get(fn);
			    	Schema.DescribeFieldResult fieldDescribe = field.getDescribe();
			    	labels.add(fieldDescribe.getLabel());
			    	widths.add(String.valueOf(fieldDescribe.getLength() * 3));
			    }
		    }
		    catch (Exception e)
		    {
		    	System.debug('UNABLE TO GENERATE LABELS:' + e);
		    }
		    		 
    }

Initial URL

                                

Initial Description

                                

Initial Title
@fractastical Field Details from fieldnames and object Name

Initial Tags

                                

Initial Language
Other