Newer Version Available
クラスおよびトリガへの Salesforce API バージョン設定
クラスまたはトリガに Salesforce API および Apex のバージョンを設定する手順は、次のとおりです。
- クラスまたはトリガのいずれかを編集して、[バージョン設定 ] をクリックします。
- Salesforce API のバージョンを選択します。このバージョンは、クラスまたはトリガに関連付けられている Apex のバージョンでもあります。
- [保存] をクリックします。
オブジェクトをメソッドコールのパラメータとして Apex クラス C1 から他のクラス C2 に渡し、C2 で Salesforce API のバージョン設定により異なる項目が公開されている場合、オブジェクトの項目は C2 のバージョン設定によって制御されます。
次の例では、Categories 項目はバージョン 13.0 の API では使用できないため、テストクラス C1 のメソッドからクラス C2 の insertIdea メソッドをコールした後に Categories 項目が null に設定されます。
最初のクラスは、Salesforce API バージョン 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}次のクラスは、Salesforce API バージョン 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}