Skip to content

Instantly share code, notes, and snippets.

@swapnilshrikhande
Created June 6, 2019 11:47
Show Gist options
  • Save swapnilshrikhande/5a853adeb2745eb1c802dc0483e5e3a5 to your computer and use it in GitHub Desktop.
Save swapnilshrikhande/5a853adeb2745eb1c802dc0483e5e3a5 to your computer and use it in GitHub Desktop.
Dynamically Pull And Create Apex Class From Github
HttpRequest req = new HttpRequest();
req.setEndpoint('https://raw.githubusercontent.com/swapnilshrikhande/nanoservices-libs/master/src/classes/HTTPNanoService.cls');
req.setMethod('GET');
Http http = new Http();
HTTPResponse res = http.send(req);
Map<String,String> createClassMap = new Map<String,String>{
'Name' => 'ExternalCalculatorNanoService'
, 'Body' => res.getBody()
};
String createClassBody = JSON.serialize(createClassMap);
HttpRequest sendReq = new HttpRequest();
sendReq.setEndpoint('https://ap15.salesforce.com/services/data/v28.0/sobjects/ApexClass');
sendReq.setBody( createClassBody );
sendReq.setMethod('POST');
sendReq.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionID());
sendReq.setHeader('Content-Type', 'application/json');
Http httpObj = new Http();
HTTPResponse result = httpObj.send(sendReq);
System.debug(result.getBody());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment