Created
June 28, 2017 06:44
-
-
Save Sunil02kumar/ce8bdb73a13b8c73fd62eeb93a22b540 to your computer and use it in GitHub Desktop.
Utility Class to find SFDC current Org API Version
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
//Utility to find SFDC current Org API Version | |
public class UtilityClassForSFDC{ | |
public static decimal findAPIVersionOfOrg(){ | |
HttpRequest req = new HttpRequest(); | |
req.setHeader('Authorization', 'Bearer ' + UserInfo.getSessionID()); | |
req.setHeader('Content-Type', 'application/json'); | |
String domainUrl=URL.getSalesforceBaseUrl().toExternalForm(); | |
system.debug('********domainUrl:'+domainUrl); | |
req.setEndpoint(domainUrl+'/services/data'); | |
req.setMethod('GET'); | |
Http h = new Http(); | |
HttpResponse res = h.send(req); | |
system.debug(res.getBody()); | |
String response=res.getBody(); | |
String apiVersion=''; | |
List<decimal> versionList=new List<decimal>(); | |
JSONParser parser = JSON.createParser(Response); | |
while (parser.nextToken() != null) { | |
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME)){ | |
String fieldName = parser.getText(); | |
if(fieldName == 'version'){ | |
parser.nextToken(); | |
versionList.add(decimal.valueof(parser.getText())); | |
} | |
} | |
} | |
versionList.sort(); | |
system.debug('*******versionList'+versionList); | |
system.debug('******Current API version:'+versionList[versionList.size()-1]); | |
return versionList[versionList.size()-1]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment