Friday, May 22, 2015

Get fields of object.

public static String GetObjectFields(String strSObjectName) {

  // Get the field names
  SObjectType sot = Schema.getGlobalDescribe().get(strSObjectName);

  if (sot == null) 
    return null;

  String theFields = '';
  List lstFields = sot.getDescribe().fields.getMap().values();

  for(Schema.SObjectField s : lstFields) {
    String theName = s.getDescribe().LocalName;
    theFields += theName + ',';
  }

  // Trim last comma
  theFields = theFields.subString(0, theFields.length() - 1);
  return theFields;
}

No comments:

Post a Comment