+ Start a Discussion
Ken KoellnerKen Koellner 

API Version of Apex/VF code and what features you get, what about limits

I always wondered why SF recordes the API version of your code.  I recently learned that it actually runs under an older version of SF if you have an old API version number.  For example, I had a VF page with version 18.0 and it wasn't getting the dependent picklist information.  I updated the number 22.0 and it works fine now.


I'm curious what features the API controls.  Is it absolutely everything?


An more specifically, if you have an old API version, will you not get newer Apex limits? 


For example, winter '12 greatly increases the heap limit and statements limit.  I need those features for a class.  If I don't change the API version of the clase from 15.0 (ancient) to 22.0, will I not get the increase limits?





Hi Ken,


When you deploy code it logs the API version in order to maintain "backwards compatibility" (I believe) - in other words if you wrote some code for v15 it will run using v15 of the API in order to prevent issues with new API versions (as you would not know exactly how v15 code would behave in a v23 world without testing it!)


The API version controls the level of functionality that you're able to access through the API - so when writing Apex classes, triggers or using webservices. Example - v15 code won't be able to access field sets, whereas v23 can.


You raise a very good question regarding the Apex limits... I have no idea how these are implemented / restricted by salesforce, perhaps someone else on here might be able to offer the answer?



Ken KoellnerKen Koellner

I did a little test.  I wrote the class below, saved it as version 10.0.  I then ran it from ad-hoc apex.  I got 50000.  Then I changed the API version and I got the same result.


What I suspect is that the Apex Limits are enforced by the Apex interpreter (I assume there is such a thing; in any case, there's some type of runtime engine that runs your code).  The Apex interpreter calls the actual API to do work that the API does.  So, I am hypothesizing that you get different API feature behavior based on the API version but not different Apex limits.   This is just a guess based on one test case.


It would be great if someone on the inside could speak up.


public with sharing class KenTestLimit {

    public static void doit() {
        Integer myInt = Limits.getLimitQueryRows();
        System.debug('xyzzy ' + myInt);



We certainly have the capability to alter limits based on API version and have done so in the past.  I'm not sure what our decision is for the new limits.  I'll see if I can get somebody who does know to answer.


API verions are used to prevent breakages with backwards-incompatible changes.  We do not run on a completely old version of the salesforce app.  The internal code is full of stuff like:


if (apiVersion < 22.0) {

  // old behavior


else {

  // new behavior



In the case of the new, expanded limits, the behavior is not tied to a version, since the higher limits are not likely to break existing code (you weren't depending on a LimitException being thrown, were you? ;) )


An example of something that does look at this versioned behavior is the type given to floating point literals by default.  I forget exactly which version it was, but in some older version, this:




...would be a double.  In more recent versions, it is a decimal.  You can qualify the literal to get a double, as in:




Since the resulting math you might do with such literals altered (to a more precise result, but still altered), this change was versioned.