Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.13 KB | None | 0 0
  1. public with sharing class LightningUtility {
  2. public static List<Schema.FieldSetMember> getFieldSetFields(String ObjectApiName,String fieldSetName) {
  3. return Schema.getGlobalDescribe().get(ObjectApiName).getDescribe().FieldSets.getMap().get(fieldSetName).getFields();
  4. }
  5. public static Boolean isCustomField(String ObjectApiName, String fieldApiName) {
  6. return Schema.getGlobalDescribe().get(ObjectApiName).getDescribe().fields.getMap().get(fieldApiName).getDescribe().isCustom();
  7. }
  8. public static String getFieldApiNames4QueryString(List<Schema.FieldSetMember> oppFields, String objectApiName) {
  9. String fieldsSel = '';
  10. for(Schema.FieldSetMember fsm : oppFields) {
  11. if(String.isBlank(fieldsSel)) {
  12. if(String.valueOf(fsm.getType()) == 'REFERENCE') {
  13. String str = fsm.getFieldPath();
  14. if(isCustomField(objectApiName,fsm.getFieldPath())) {
  15. fieldsSel = str+','+str.left(str.length()-1)+'r.Name';
  16. }
  17. else {
  18. fieldsSel = str+','+str.left(str.length()-2)+'.Name';
  19. }
  20. }
  21. else {
  22. fieldsSel = fsm.getFieldPath();
  23. }
  24. }
  25. else {
  26. if(String.valueOf(fsm.getType()) == 'REFERENCE') {
  27. String str = fsm.getFieldPath();
  28. if(isCustomField(objectApiName,fsm.getFieldPath())) {
  29. fieldsSel += ','+str+','+str.left(str.length()-1)+'r.Name';
  30. }
  31. else {
  32. fieldsSel += ','+str+','+str.left(str.length()-2)+'.Name';
  33. }
  34. }
  35. else {
  36. fieldsSel += ','+fsm.getFieldPath();
  37. }
  38. }
  39. }
  40. return fieldsSel;
  41. }
  42. public static List<String> getFieldApisLstOfFieldSet(List<Schema.FieldSetMember> oppFields) {
  43. List<String> fieldApiNames = new List<String>();
  44. for(Schema.FieldSetMember fsm : oppFields) {
  45. fieldApiNames.add(fsm.getFieldPath());
  46. }
  47. return fieldApiNames;
  48. }
  49. public static List<KayAndValue> getFieldApisAndDTyesLstOfFieldSet(List<Schema.FieldSetMember> oppFields, String objectApi) {
  50. List<KayAndValue> fieldApiDataTypes = new List<KayAndValue>();
  51. for(Schema.FieldSetMember fsm : oppFields) {
  52. KayAndValue kv = new KayAndValue(fsm.getFieldPath(),String.valueOf(fsm.getType()),isCustomField(objectApi,fsm.getFieldPath()));
  53. fieldApiDataTypes.add(kv);
  54. }
  55. return fieldApiDataTypes;
  56. }
  57. public static List<String> getFieldLabelsLstOfFieldSet(List<Schema.FieldSetMember> oppFields, String objectApiName) {
  58. List<String> fieldLabelNames = new List<String>();
  59. for(Schema.FieldSetMember fsm : oppFields) {
  60. if(String.valueOf(fsm.getType()) == 'REFERENCE' && !isCustomField(objectApiName,fsm.getFieldPath())) {
  61. fieldLabelNames.add(fsm.getLabel().left(fsm.getLabel().length()-2)+' Name');
  62. }
  63. else if(String.valueOf(fsm.getType()) == 'ID') {
  64. fieldLabelNames.add('Actions');
  65. }
  66. else {
  67. fieldLabelNames.add(fsm.getLabel());
  68. }
  69. }
  70. return fieldLabelNames;
  71. }
  72. public static String getQueryString(String objectApiName, String selFieldsString, String limitSize, String offsetSize) {
  73. system.debug('@@limitSize: '+limitSize);
  74. String limitSizeStr;
  75. if(limitSize == null) {
  76. limitSizeStr = String.valueOf(Limits.getLimitQueryRows());
  77. }
  78. else {
  79. limitSizeStr = limitSize;
  80. }
  81. system.debug('limitSizeStr: '+limitSizeStr);
  82. String finalOffset = '';
  83. if(String.isNotBlank(offsetSize)) {
  84. finalOffset = ' offset '+offsetSize;
  85. }
  86. return 'select '+selFieldsString+' from '+objectApiName + ' Limit '+limitSizeStr+finalOffset;
  87. }
  88.  
  89. public class KayAndValue {
  90. @AuraEnabled
  91. public String fieldDataType;
  92. @AuraEnabled
  93. public String fieldApiName;
  94. @AuraEnabled
  95. public Boolean isCustom;
  96. public KayAndValue(String fieldApiName, String fieldDataType, Boolean isCustom) {
  97. this.fieldApiName = fieldApiName;
  98. this.fieldDataType = fieldDataType;
  99. this.isCustom = isCustom;
  100. }
  101. }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement