---
schema_version: "1"
id: b1429dcd8f86b55b4c1d20fee70432d72baf1ef90ab1d68896d373ca002fb961
title: |-
  Setting the Salesforce API Version for Classes and
      Triggers
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/apexcode/apex_classes_version_settings_api.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_version_settings_api.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 937d9082fca29ce6c0a5de60a9ade7899b7ccad7f3a10c85f788efee23600eda
---
# Setting the Salesforce API Version for Classes and Triggers

To set the Salesforce API and Apex version for a class or trigger:

1. Edit either a class or trigger, and click **Version Settings**.
2. Select the Version of the Salesforce API. This version is also the version of Apex associated with the class or trigger.
3. Click **Save**.

If you pass an object as a parameter in a method call from one Apex class, C1, to another class, C2, and C2 has different fields exposed due to the Salesforce API version setting, the fields in the objects are controlled by the version settings of C2.

In this example, the Categories field is set to null after calling the insertIdea method in class C2 from a method in the test class C1, because the Categories field isn’t available in version 13.0 of the API.

The first class is saved using Salesforce API version 13.0:

// This class is saved using Salesforce API version 13.0
// Version 13.0 does not include the Idea.categories field
public with sharing class C2 {
    public Idea insertIdea(Idea a) {
        insert as user a; // category field set to null on insert
        
        // retrieve the new idea
        Idea insertedIdea = \[SELECT title FROM Idea WHERE Id =:a.Id WITH USER\_MODE\];
        
        return insertedIdea;
    }
}

The following class is saved using Salesforce API version 16.0:

@IsTest
// This class is bound to API version 16.0 by Version Settings
private with sharing class C1 {
    @IsTest
    static void testC2Method() {
        Idea i = new Idea();
        i.CommunityId = '09aD000000004YCIAY';
        i.Title = 'Testing Version Settings';
        i.Body = 'Categories field is included in API version 16.0';
        i.Categories = 'test';

        C2 c2 = new C2();
        Idea returnedIdea = c2.insertIdea(i);
        // retrieve the new idea
        Idea ideaMoreFields = \[SELECT title, categories FROM Idea
             WHERE Id = :returnedIdea.Id WITH USER\_MODE\];

        // assert that the categories field from the object created
        // in this class is not null
        Assert.isNotNull(i.Categories);
        // assert that the categories field created in C2 is null
        Assert.isNull(ideaMoreFields.Categories);
    }
}