Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@arun12209
Last active December 22, 2018 08:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arun12209/8e456cebafe4faebe1fea4cc368be811 to your computer and use it in GitHub Desktop.
Save arun12209/8e456cebafe4faebe1fea4cc368be811 to your computer and use it in GitHub Desktop.
searchMetadataCntrl
/* Name: ToolingCntrl
* Description: This Apex class makes callout to Salesforce Tooling Api and get the metadata information about the objects.
* Created By: Arun Kumar
*/
public class searchMetadataCntrl {
@AuraEnabled
public static string GetMetaData(string type){
HttpRequest req = new HttpRequest();
String session_id;
if(!test.isRunningTest()){
session_id = UtilsClass.getSessionIdFromVFPage(Page.SessionIdPage);
}
system.debug('Session ID: ' +session_id);
req.setHeader('Authorization', 'Bearer ' + session_id);
string domainUrl=URL.getSalesforceBaseUrl().toExternalForm();
string endpoint='';
if(type=='ApexClass & ApexTrigger'){
endpoint='select+id,ApexClassOrTrigger.Name,NumLinesCovered,NumLinesUncovered+from+ApexCodeCoverageAggregate';
}
else if(type=='ValidationRule'){
endpoint='Select+id,ErrorDisplayField,createdDate,ValidationName+from+ValidationRule';
}
else if(type=='WorkflowRule'){
endpoint='Select+id,Name+from+WorkflowRule';
}
else if(type=='VisualforcePages'){
endpoint='Select+id,Name,Description,ControllerType,ApiVersion+from+ApexPage';
}else if(type=='Static Resource'){
endpoint='select+id,Name,ContentType+from+StaticResource';
}else if(type=='Email Template'){
endpoint='select+id,Name,UIType+from+EmailTemplate';
}else if(type=='Documents'){
endpoint='select+id,Name,Type,Url+from+Document';
}else if(type=='Visualforce Component'){
endpoint='select+id,name+from+ApexComponent';
}
req.setEndpoint(domainUrl+'/services/data/v42.0/tooling/query/?q='+endpoint);
req.setMethod('GET');
Http h = new Http();
try{
HttpResponse response = h.send(req);
system.debug(response.getBody());
return response.getBody();
}
catch(Exception e){
string exceptionString=e.getMessage();
system.debug('Exception: '+exceptionString);
return exceptionString;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment