Created
June 6, 2019 11:47
-
-
Save swapnilshrikhande/5a853adeb2745eb1c802dc0483e5e3a5 to your computer and use it in GitHub Desktop.
Dynamically Pull And Create Apex Class From Github
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
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