Skip to content

Instantly share code, notes, and snippets.

@Sunil02kumar
Created July 4, 2023 15:43
Show Gist options
  • Save Sunil02kumar/e75b3f63d16d3f5d55734e2d70230fbf to your computer and use it in GitHub Desktop.
Save Sunil02kumar/e75b3f63d16d3f5d55734e2d70230fbf to your computer and use it in GitHub Desktop.
public class SK_ToolingAPIUtility {
@AuraEnabled
public static List<checkboxGroupValuesWrapper> findAllObjects(string selOrgNCName,string namespacePrefix,string objName){
system.debug('****selOrgNCName:'+selOrgNCName);
system.debug('****NamespacePrefix:'+namespacePrefix);
system.debug('****objName:'+objName);
List<checkboxGroupValuesWrapper> returnList=new List<checkboxGroupValuesWrapper>();
try {
string URIForObjects='/services/data/v54.0/tooling/query/?q=Select+id,NamespacePrefix,MasterLabel,QualifiedApiName,DeveloperName+from+Entitydefinition+where+IsCustomSetting=false+and+IsCustomizable=true';
string endpointURL='callout:'+selOrgNCName+URIForObjects;
//endpointURL='select+id+from+Account';
if(string.isNotBlank(NamespacePrefix)){
endpointURL=endpointURL+'+AND+NamespacePrefix=\''+NamespacePrefix+'\'';
}if(string.isNotBlank(objName)){
endpointURL=endpointURL+'+AND+MasterLabel+Like+\'%25'+objName+'%25\'';
}
endpointURL=endpointURL+'+order+by+MasterLabel';
system.debug('***endpointURL:'+endpointURL);
HttpRequest req = new HttpRequest();
req.setEndpoint(endpointURL);
req.setMethod('GET');
Http http = new Http();
HTTPResponse res = http.send(req);
DM_ObjectWrapper JSONDetails= DM_ObjectWrapper.parse(res.getBody());
System.debug('****object count-:'+JSONDetails.records.size());
for(cls_records eachRec:JSONDetails.records){
//System.debug('****eachrec-:'+eachRec);
checkboxGroupValuesWrapper objInfo=new checkboxGroupValuesWrapper();
objInfo.label=eachRec.MasterLabel +'('+eachRec.QualifiedApiName+')';
objInfo.value=eachRec.QualifiedApiName;
returnList.add(objInfo);
system.debug('*****objInfo:'+objInfo);
}
} catch (Exception ex) {
system.debug('****error-'+ex.getMessage());
}
system.debug('*****returnList:'+returnList);
return returnList;
}
public class checkboxGroupValuesWrapper{
@AuraEnabled
public string label;
@AuraEnabled
public string value;
}
public class DM_ObjectWrapper {
public Integer size;
public Integer totalSize;
public boolean done;
public string queryLocator;
public String entityTypeName;
public cls_records[] records;
}
public class cls_records {
public cls_attributes attributes;
public String Id;
public string NamespacePrefix;
public String MasterLabel;
public String QualifiedApiName;
public String DeveloperName;
}
public class cls_attributes {
public String type;
public String url;
}
public static DM_ObjectWrapper parse(String json){
return (DM_ObjectWrapper) System.JSON.deserialize(json, DM_ObjectWrapper.class);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment