Newer Version Available
Setting the Salesforce API Version for Classes and Triggers
To set the Salesforce API and Apex version for a class or trigger:
- Edit either a class or trigger, and click Version Settings.
- Select the Version of the Salesforce API. This is also the version of Apex associated with the class or trigger.
- 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.
Using the following 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 is not available in version 13.0 of the API.
The first class is saved using Salesforce API version 13.0:
1swfobject.registerObject("clippy.codeblock-0", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17// This class is saved using Salesforce API version 13.0
18// Version 13.0 does not include the Idea.categories field
19global class C2
20{
21 global Idea insertIdea(Idea a) {
22 insert a; // category field set to null on insert
23
24 // retrieve the new idea
25 Idea insertedIdea = [SELECT title FROM Idea WHERE Id =:a.Id];
26
27 return insertedIdea;
28 }
29}The following class is saved using Salesforce API version 16.0:
1swfobject.registerObject("clippy.codeblock-1", "9");
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17@isTest
18// This class is bound to API version 16.0 by Version Settings
19private class C1
20{
21 static testMethod void testC2Method() {
22 Idea i = new Idea();
23 i.CommunityId = '09aD000000004YCIAY';
24 i.Title = 'Testing Version Settings';
25 i.Body = 'Categories field is included in API version 16.0';
26 i.Categories = 'test';
27
28 C2 c2 = new C2();
29 Idea returnedIdea = c2.insertIdea(i);
30 // retrieve the new idea
31 Idea ideaMoreFields = [SELECT title, categories FROM Idea
32 WHERE Id = :returnedIdea.Id];
33
34 // assert that the categories field from the object created
35 // in this class is not null
36 System.assert(i.Categories != null);
37 // assert that the categories field created in C2 is null
38 System.assert(ideaMoreFields.Categories == null);
39 }
40}