Created
September 21, 2017 01:39
-
-
Save karanrajs/5b7cf12ad4cf46e1a54a3151b4a7d2b8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@AuraEnabled public static lightningTableWraper getsObjectRecords(String ObjectName,String fieldstoget){ | |
List<String> lstfieldstoget = fieldstoget.split(','); | |
List<lightningTableColumnWrapper> lstTableColumn = new list<lightningTableColumnWrapper> (); | |
DescribeSObjectResult objResult = Schema.getGlobalDescribe().get(ObjectName).getDescribe(); | |
for(String field : lstfieldstoget){ | |
lightningTableColumnWrapper colWrapper = new lightningTableColumnWrapper(); | |
DescribeFieldResult fieldResult = objResult.fields.getMap().get(field).getDescribe(); | |
colWrapper.label = fieldResult.getLabel(); | |
colWrapper.fieldName = fieldResult.getName(); | |
colWrapper.type = String.valueof(fieldResult.getType()).toLowerCase(); | |
colWrapper.sortable = true; | |
lstTableColumn.add(colWrapper); | |
} | |
String queryString = 'Select '+ String.escapeSingleQuotes(String.join(lstfieldstoget,','))+ | |
' from '+ String.escapeSingleQuotes(ObjectName) + ' Limit 10'; | |
LightningTableWraper ltngTableWrapper = new LightningTableWraper(); | |
ltngTableWrapper.tableRecord = database.query(queryString); | |
ltngTableWrapper.tableColumn = lstTableColumn; | |
return ltngTableWrapper; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment