@fractastical Field Details from fieldnames and object Name


/ Published in: Other
Save to your folder(s)



Copy this code and paste it in your HTML
  1. public void getLabelsAndWidthsfromFields(List<String> fieldNames, String objectName)
  2. {
  3. labels = new List<String>();
  4. widths = new List<String>();
  5.  
  6. try {
  7. Map<String, Schema.SObjectType> gd = Schema.getGlobalDescribe();
  8. SObjectType sot = gd.get(objectName);
  9. Map<String, SObjectField> fields = sot.getDescribe().fields.getMap();
  10. List<SObjectField> fieldtokens = fields.values();
  11. for(String fn : fieldNames)
  12. {
  13. SObjectField field = fields.get(fn);
  14. Schema.DescribeFieldResult fieldDescribe = field.getDescribe();
  15. labels.add(fieldDescribe.getLabel());
  16. widths.add(String.valueOf(fieldDescribe.getLength() * 3));
  17. }
  18. }
  19. catch (Exception e)
  20. {
  21. System.debug('UNABLE TO GENERATE LABELS:' + e);
  22. }
  23.  
  24. }
  25.  

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.