クラスおよびトリガへの 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 を使用して保存されています。
1// This class is saved using Salesforce API version 13.0
2// Version 13.0 does not include the Idea.categories field
3global class C2
4{
5 global Idea insertIdea(Idea a) {
6 insert a; // category field set to null on insert
7
8 // retrieve the new idea
9 Idea insertedIdea = [SELECT title FROM Idea WHERE Id =:a.Id];
10
11 return insertedIdea;
12 }
13}次のクラスは、Salesforce API バージョン 16.0 を使用して保存されています。
1@isTest
2// This class is bound to API version 16.0 by Version Settings
3private class C1
4{
5 static testMethod void testC2Method() {
6 Idea i = new Idea();
7 i.CommunityId = '09aD000000004YCIAY';
8 i.Title = 'Testing Version Settings';
9 i.Body = 'Categories field is included in API version 16.0';
10 i.Categories = 'test';
11
12 C2 c2 = new C2();
13 Idea returnedIdea = c2.insertIdea(i);
14 // retrieve the new idea
15 Idea ideaMoreFields = [SELECT title, categories FROM Idea
16 WHERE Id = :returnedIdea.Id];
17
18 // assert that the categories field from the object created
19 // in this class is not null
20 System.assert(i.Categories != null);
21 // assert that the categories field created in C2 is null
22 System.assert(ideaMoreFields.Categories == null);
23 }
24}