0

I have tried to get latest api version through /service/data . I have refered this link also Find current API version in Apex

But when i used latest version in this :

final PageReference theUrl = new PageReference(SERVER_URL + '/services/data/+version+/query');
theUrl.getParameters().put('q','Select Name From ApexClass');

Its throwing 404 error response. Any help would be appreciated.

1
  • If you get the API version using rest API, you need to provide proper base URL. I think when you run get base URL from VF page it adds c. or a {namespace}. in URL depending if org has a namespace. Try hardcoding the URL to check if its issue with URL:?
    – Raul
    Commented Sep 29, 2017 at 10:50

2 Answers 2

2

You forgot a couple of quotation marks, so you're trying to call the literal url:

/services/data/+version+/query

Instead of what you intended:

/services/data/40.0/query

You need to add the missing quotes:

final PageReference theUrl = new PageReference(SERVER_URL + '/services/data/'+version+'/query');
1

You can query the API version like this as well:

ApexClass classObj = [SELECT ApiVersion FROM ApexClass WHERE Name = 'YourClassName'];
System.debug(classObj.ApiVersion);
1
  • ..Thanks for the reply ...But it will give me APex class api version.it is giving me apex class api version only.
    – emy
    Commented Sep 29, 2017 at 11:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .