function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sdudasduda 

APEX Testing Error

If you create two or more of the same objects in a test method, there is a custom-field lookup problem w/ picklists. When you try to query for the second object using the picklist value, it cannot be found. Any test method following will have the same problems.

Example:

Object X
   Fields:  TestPick ( Picklist ), Values: 'A', 'B', 'C'
                TestText ( Text )

Class A
    Test Method 1:
       1. Create Custom Object X, TestPick = 'D', TestText = 'Test'
           1a. Can Query for Custom Object Using Standard Field or non-picklist.
                 - SELECT ID FROM X__c WHERE TestText = 'Test'
           1b. Can Query for Custom Object Using Custom Picklist Field.    <-- Custom-field query only works here
                 - SELECT ID FROM X__c WHERE TestPick = 'D'
       2. Create Custom Object X, TestPick = 'E', TestText = 'Test2'
           2a. Can Query for Custom Object Using Standard Field or non-picklist.
                 - SELECT ID FROM X__c WHERE TestText = 'Test2'
           2b. Can't Query for Custom Object Using Custom Picklist Field.
                 - SELECT ID FROM X__c WHERE TestPick = 'E'
    Test Method 2:
       1. Create Custom Object X, TestPick = 'F', TestText = 'Test3'
           1a. Can Query for Custom Object Using Standard Field.
                 - SELECT ID FROM X__c WHERE TestText = 'Test3'
           1b. Can't Query for Custom Object Using Custom Picklist Field.
                 - SELECT ID FROM X__c WHERE TestPick = 'F'

Class B
    Test Method 1:
       1. Create Custom Object X, TestPick = 'D', TestText = 'Test'
           1a. Can Query for Custom Object Using Standard Field or non-picklist.
                 - SELECT ID FROM X__c WHERE TestText = 'Test'
           1b. Can Query for Custom Object Using Custom Picklist Field.
                 - SELECT ID FROM X__c WHERE TestPick = 'D'
       2. Create Custom Object X, TestPick = 'E', TestText = 'Test2'
           2a. Can Query for Custom Object Using Standard Field or non-picklist.
                 - SELECT ID FROM X__c WHERE TestText = 'Test2'
           2b. Can't Query for Custom Object Using Custom Picklist Field.
                 - SELECT ID FROM X__c WHERE TestPick = 'E'
    Test Method 2:
       1. Create Custom Object X, TestPick = 'F', TestText = 'Test3'
           1a. Can Query for Custom Object Using Standard Field.
                 - SELECT ID FROM X__c WHERE TestText = 'Test3'
           1b. Can't Query for Custom Object Using Custom Picklist Field.
                 - SELECT ID FROM X__c WHERE TestPick = 'F'


When deploying code to Sandbox or Producton enviroment, you encounter the problem above.
Note: If you deploy to Sandbox without running all tests, you will encounter the problem below the FIRST time you run tests in Sandbox. The SECOND time you run the test in sandbox, the problem below will be fixed.

Below is an example using a custom object "Program__c" w/ the custom picklist field "Zone__c". This can be modified replicate the issue with any object w/ custom picklist fields. Also, Class B, Test 1, Query 1a will pass on the first TEST.

Apex Code:
public class APEXTestMethod {

public static testMethod void runTests1() {

Program__c prog = new Program__c();
prog.Zone__c = 'APEXTestMethod_Test1_A';
insert prog;

System.debug( 'APEXTestMethod Test1_A Lookup By ID' );
System.debug( [SELECT p.Id, p.Zone__c FROM Program__c p WHERE Id = :prog.Id] );

System.debug( 'APEXTestMethod Test1_A Lookup By Custom Field' );
System.debug( [SELECT p.Id, p.Zone__c FROM Program__c p WHERE p.Zone__c = 'APEXTestMethod_Test1_A'] );

System.debug( 'APEXTestMethod Test1_A Lookup By Custom Field' );
System.debug( [SELECT p.Id, p.Zone__c FROM Program__c p WHERE p.Zone__c = 'APEXTestMethod_Test1_A'] );




prog = new Program__c();
prog.Zone__c = 'APEXTestMethod_Test1_B';
insert prog;

System.debug( 'APEXTestMethod Test1_B Lookup By Id' );
System.debug( [SELECT p.Id, p.Zone__c FROM Program__c p WHERE Id = :prog.Id] );

System.debug( 'APEXTestMethod Test1_B Lookup By Custom Field' );
// Should Find 1 Record, But Finds None
System.debug( [SELECT p.Id, p.Zone__c FROM Program__c p WHERE p.Zone__c = 'APEXTestMethod_Test1_B'] );

}

public static testMethod void runTests2() {

Program__c prog = new Program__c();
prog.Zone__c = 'APEXTestMethod_Test2_A';
insert prog;

System.debug( 'APEXTestMethod Test2_A Lookup By ID' );
System.debug( [SELECT p.Id, p.Zone__c FROM Program__c p WHERE Id = :prog.Id] );

System.debug( 'APEXTestMethod Test2_A Lookup By Custom Field' );
// Should Find 1 Record, But Finds None
System.debug( [SELECT p.Id, p.Zone__c FROM Program__c p WHERE p.Zone__c = 'APEXTestMethod_Test2_A'] );

prog = new Program__c();
prog.Zone__c = 'APEXTestMethod_Test2_B';
insert prog;

System.debug( 'APEXTestMethod Test2_B Lookup By Id' );
System.debug( [SELECT p.Id, p.Zone__c FROM Program__c p WHERE Id = :prog.Id] );

System.debug( 'APEXTestMethod Test2_B Lookup By Custom Field' );
// Should Find 1 Record, But Finds None
System.debug( [SELECT p.Id, p.Zone__c FROM Program__c p WHERE p.Zone__c = 'APEXTestMethod_Test2_B'] );

}

}


public class APEXTestMethod2 {

public static testMethod void runTests1() {

Program__c prog = new Program__c();
prog.Zone__c = 'APEXTestMethod2_Test1_A';
insert prog;

System.debug( 'APEXTestMethod2 Test1_A Lookup By ID' );
System.debug( [SELECT p.Id, p.Zone__c FROM Program__c p WHERE Id = :prog.Id] );

System.debug( 'APEXTestMethod2 Test1_A Lookup By Custom Field' );
// Should Find 1 Record, But Finds None
System.debug( [SELECT p.Id, p.Zone__c FROM Program__c p WHERE p.Zone__c = 'APEXTestMethod2_Test1_A'] );

System.debug( 'APEXTestMethod2 Test1_A Lookup By Custom Field' );
// Should Find 1 Record, But Finds None
System.debug( [SELECT p.Id, p.Zone__c FROM Program__c p WHERE p.Zone__c = 'APEXTestMethod2_Test1_A'] );




prog = new Program__c();
prog.Zone__c = 'APEXTestMethod2_Test1_B';
insert prog;

System.debug( 'APEXTestMethod2 Test1_B Lookup By Id' );
System.debug( [SELECT p.Id, p.Zone__c FROM Program__c p WHERE Id = :prog.Id] );

System.debug( 'APEXTestMethod2 Test1_B Lookup By Custom Field' );
// Should Find 1 Record, But Finds None
System.debug( [SELECT p.Id, p.Zone__c FROM Program__c p WHERE p.Zone__c = 'APEXTestMethod2_Test1_B'] );

}

public static testMethod void runTests2() {

Program__c prog = new Program__c();
prog.Zone__c = 'APEXTestMethod2_Test2_A';
insert prog;

System.debug( 'APEXTestMethod2 Test2_A Lookup By ID' );
System.debug( [SELECT p.Id, p.Zone__c FROM Program__c p WHERE Id = :prog.Id] );

System.debug( 'APEXTestMethod2 Test2_A Lookup By Custom Field' );
// Should Find 1 Record, But Finds None
System.debug( [SELECT p.Id, p.Zone__c FROM Program__c p WHERE p.Zone__c = 'APEXTestMethod2_Test2_A'] );

prog = new Program__c();
prog.Zone__c = 'APEXTestMethod2_Test2_B';
insert prog;

System.debug( 'APEXTestMethod2 Test2_B Lookup By Id' );
System.debug( [SELECT p.Id, p.Zone__c FROM Program__c p WHERE Id = :prog.Id] );

System.debug( 'APEXTestMethod2 Test2_B Lookup By Custom Field' );
// Should Find 1 Record, But Finds None
System.debug( [SELECT p.Id, p.Zone__c FROM Program__c p WHERE p.Zone__c = 'APEXTestMethod2_Test2_B'] );

}



}


Debug Log Output:

[sf:deploy]
[sf:deploy] *** Beginning Test 1: APEXTestMethod.public static testMethod void runTests1()
[sf:deploy]
[sf:deploy] 20081201225632.568:Class.APEXTestMethod.runTests1: line 7, column 13: Insert: SOBJECT:Program__c
[sf:deploy] 20081201225632.568:Class.APEXTestMethod.runTests1: line 7, column 13:     DML Operation executed in 197 ms
[sf:deploy] 20081201225632.568:Class.APEXTestMethod.runTests1: line 9, column 10: APEXTestMethod Test1_A Lookup By ID
[sf:deploy] 20081201225632.568:Class.APEXTestMethod.runTests1: line 10, column 24: SOQL query with 1 row finished in 14 ms
[sf:deploy] 20081201225632.568:Class.APEXTestMethod.runTests1: line 10, column 10: (Program__c:{Zone__c=APEXTestMethod_Test1_A, Id=a0H30000000ikWnEAI})
[sf:deploy] 20081201225632.568:Class.APEXTestMethod.runTests1: line 12, column 10: APEXTestMethod Test1_A Lookup By Custom Field
[sf:deploy] 20081201225632.568:Class.APEXTestMethod.runTests1: line 13, column 24: SOQL query with 1 row finished in 23 ms
[sf:deploy] 20081201225632.568:Class.APEXTestMethod.runTests1: line 13, column 10: (Program__c:{Zone__c=APEXTestMethod_Test1_A, Id=a0H30000000ikWnEAI})
[sf:deploy] 20081201225632.568:Class.APEXTestMethod.runTests1: line 15, column 10: APEXTestMethod Test1_A Lookup By Custom Field
[sf:deploy] 20081201225632.568:Class.APEXTestMethod.runTests1: line 16, column 24: SOQL query with 1 row finished in 20 ms
[sf:deploy] 20081201225632.568:Class.APEXTestMethod.runTests1: line 16, column 10: (Program__c:{Zone__c=APEXTestMethod_Test1_A, Id=a0H30000000ikWnEAI})
[sf:deploy] 20081201225632.568:Class.APEXTestMethod.runTests1: line 23, column 13: Insert: SOBJECT:Program__c
[sf:deploy] 20081201225632.568:Class.APEXTestMethod.runTests1: line 23, column 13:     DML Operation executed in 121 ms
[sf:deploy] 20081201225632.568:Class.APEXTestMethod.runTests1: line 25, column 10: APEXTestMethod Test1_B Lookup By Id
[sf:deploy] 20081201225632.568:Class.APEXTestMethod.runTests1: line 26, column 24: SOQL query with 1 row finished in 14 ms
[sf:deploy] 20081201225632.568:Class.APEXTestMethod.runTests1: line 26, column 10: (Program__c:{Zone__c=APEXTestMethod_Test1_B, Id=a0H30000000ikWoEAI})
[sf:deploy] 20081201225632.568:Class.APEXTestMethod.runTests1: line 28, column 10: APEXTestMethod Test1_B Lookup By Custom Field
[sf:deploy] 20081201225632.568:Class.APEXTestMethod.runTests1: line 29, column 24: SOQL query with 0 rows finished in 18 ms
[sf:deploy] 20081201225632.568:Class.APEXTestMethod.runTests1: line 29, column 10: ()
[sf:deploy] 20081201225632.568:Class.APEXTestMethod: line 3, column 35:     returning from end of method public static testMethod void runTests1() in 410 ms
[sf:deploy]
[sf:deploy] Cumulative resource usage:
[sf:deploy]
[sf:deploy] Resource usage for namespace: (default)
[sf:deploy] Number of SOQL queries: 5 out of 100
[sf:deploy] Number of query rows: 4 out of 500
[sf:deploy] Number of SOSL queries: 0 out of 20
[sf:deploy] Number of DML statements: 2 out of 100
[sf:deploy] Number of DML rows: 2 out of 500
[sf:deploy] Number of script statements: 16 out of 200000
[sf:deploy] Maximum heap size: 0 out of 500000
[sf:deploy] Number of callouts: 0 out of 10
[sf:deploy] Number of Email Invocations: 0 out of 10
[sf:deploy] Number of fields describes: 0 out of 10
[sf:deploy] Number of record type describes: 0 out of 10
[sf:deploy] Number of child relationships describes: 0 out of 10
[sf:deploy] Number of picklist describes: 0 out of 10
[sf:deploy] Number of future calls: 0 out of 10
[sf:deploy] Number of find similar calls: 0 out of 10
[sf:deploy] Number of System.runAs() invocations: 0 out of 20
[sf:deploy]
[sf:deploy] Total email recipients queued to be sent : 0
[sf:deploy] *** Ending Test APEXTestMethod.public static testMethod void runTests1()
[sf:deploy]





[sf:deploy] *** Beginning Test 2: APEXTestMethod.public static testMethod void runTests2()
[sf:deploy]
[sf:deploy] 20081201225632.982:Class.APEXTestMethod.runTests2: line 37, column 13: Insert: SOBJECT:Program__c
[sf:deploy] 20081201225632.982:Class.APEXTestMethod.runTests2: line 37, column 13:     DML Operation executed in 118 ms
[sf:deploy] 20081201225632.982:Class.APEXTestMethod.runTests2: line 39, column 10: APEXTestMethod Test2_A Lookup By ID
[sf:deploy] 20081201225632.982:Class.APEXTestMethod.runTests2: line 40, column 24: SOQL query with 1 row finished in 12 ms
[sf:deploy] 20081201225632.982:Class.APEXTestMethod.runTests2: line 40, column 10: (Program__c:{Zone__c=APEXTestMethod_Test2_A, Id=a0H30000000ikWpEAI})
[sf:deploy] 20081201225632.982:Class.APEXTestMethod.runTests2: line 42, column 10: APEXTestMethod Test2_A Lookup By Custom Field
[sf:deploy] 20081201225632.982:Class.APEXTestMethod.runTests2: line 43, column 24: SOQL query with 0 rows finished in 14 ms
[sf:deploy] 20081201225632.982:Class.APEXTestMethod.runTests2: line 43, column 10: ()
[sf:deploy] 20081201225632.982:Class.APEXTestMethod.runTests2: line 47, column 13: Insert: SOBJECT:Program__c
[sf:deploy] 20081201225632.982:Class.APEXTestMethod.runTests2: line 47, column 13:     DML Operation executed in 114 ms
[sf:deploy] 20081201225632.982:Class.APEXTestMethod.runTests2: line 49, column 10: APEXTestMethod Test2_B Lookup By Id
[sf:deploy] 20081201225632.982:Class.APEXTestMethod.runTests2: line 50, column 24: SOQL query with 1 row finished in 15 ms
[sf:deploy] 20081201225632.982:Class.APEXTestMethod.runTests2: line 50, column 10: (Program__c:{Zone__c=APEXTestMethod_Test2_B, Id=a0H30000000ikWqEAI})
[sf:deploy] 20081201225632.982:Class.APEXTestMethod.runTests2: line 52, column 10: APEXTestMethod Test2_B Lookup By Custom Field
[sf:deploy] 20081201225632.982:Class.APEXTestMethod.runTests2: line 53, column 24: SOQL query with 0 rows finished in 17 ms
[sf:deploy] 20081201225632.982:Class.APEXTestMethod.runTests2: line 53, column 10: ()
[sf:deploy]
[sf:deploy] Class.APEXTestMethod.runTests2: line 55, column 9
[sf:deploy]
[sf:deploy]
[sf:deploy] Cumulative resource usage:
[sf:deploy]
[sf:deploy] Resource usage for namespace: (default)
[sf:deploy] Number of SOQL queries: 4 out of 100
[sf:deploy] Number of query rows: 2 out of 500
[sf:deploy] Number of SOSL queries: 0 out of 20
[sf:deploy] Number of DML statements: 2 out of 100
[sf:deploy] Number of DML rows: 2 out of 500
[sf:deploy] Number of script statements: 15 out of 200000
[sf:deploy] Maximum heap size: 0 out of 500000
[sf:deploy] Number of callouts: 0 out of 10
[sf:deploy] Number of Email Invocations: 0 out of 10
[sf:deploy] Number of fields describes: 0 out of 10
[sf:deploy] Number of record type describes: 0 out of 10
[sf:deploy] Number of child relationships describes: 0 out of 10
[sf:deploy] Number of picklist describes: 0 out of 10
[sf:deploy] Number of future calls: 0 out of 10
[sf:deploy] Number of find similar calls: 0 out of 10
[sf:deploy] Number of System.runAs() invocations: 0 out of 20
[sf:deploy]
[sf:deploy] Total email recipients queued to be sent : 0
[sf:deploy] Stack frame variables and sizes:
[sf:deploy]   Frame0
[sf:deploy]
[sf:deploy] *** Ending Test APEXTestMethod.public static testMethod void runTests2()
[sf:deploy]




[sf:deploy] *** Beginning Test 3: APEXTestMethod2.public static testMethod void runTests1()
[sf:deploy]
[sf:deploy] 20081201225633.282:Class.APEXTestMethod2.runTests1: line 7, column 13: Insert: SOBJECT:Program__c
[sf:deploy] 20081201225633.282:Class.APEXTestMethod2.runTests1: line 7, column 13:     DML Operation executed in 108 ms
[sf:deploy] 20081201225633.282:Class.APEXTestMethod2.runTests1: line 9, column 10: APEXTestMethod2 Test1_A Lookup By ID
[sf:deploy] 20081201225633.282:Class.APEXTestMethod2.runTests1: line 10, column 24: SOQL query with 1 row finished in 14 ms
[sf:deploy] 20081201225633.282:Class.APEXTestMethod2.runTests1: line 10, column 10: (Program__c:{Zone__c=APEXTestMethod2_Test1_A, Id=a0H30000000ikWrEAI})
[sf:deploy] 20081201225633.282:Class.APEXTestMethod2.runTests1: line 12, column 10: APEXTestMethod2 Test1_A Lookup By Custom Field
[sf:deploy] 20081201225633.282:Class.APEXTestMethod2.runTests1: line 13, column 24: SOQL query with 0 rows finished in 18 ms
[sf:deploy] 20081201225633.282:Class.APEXTestMethod2.runTests1: line 13, column 10: ()
[sf:deploy] 20081201225633.282:Class.APEXTestMethod2.runTests1: line 15, column 10: APEXTestMethod2 Test1_A Lookup By Custom Field
[sf:deploy] 20081201225633.282:Class.APEXTestMethod2.runTests1: line 16, column 24: SOQL query with 0 rows finished in 16 ms
[sf:deploy] 20081201225633.282:Class.APEXTestMethod2.runTests1: line 16, column 10: ()
[sf:deploy] 20081201225633.282:Class.APEXTestMethod2.runTests1: line 23, column 13: Insert: SOBJECT:Program__c
[sf:deploy] 20081201225633.282:Class.APEXTestMethod2.runTests1: line 23, column 13:     DML Operation executed in 109 ms
[sf:deploy] 20081201225633.282:Class.APEXTestMethod2.runTests1: line 25, column 10: APEXTestMethod2 Test1_B Lookup By Id
[sf:deploy] 20081201225633.282:Class.APEXTestMethod2.runTests1: line 26, column 24: SOQL query with 1 row finished in 10 ms
[sf:deploy] 20081201225633.282:Class.APEXTestMethod2.runTests1: line 26, column 10: (Program__c:{Zone__c=APEXTestMethod2_Test1_B, Id=a0H30000000ikWsEAI})
[sf:deploy] 20081201225633.282:Class.APEXTestMethod2.runTests1: line 28, column 10: APEXTestMethod2 Test1_B Lookup By Custom Field
[sf:deploy] 20081201225633.282:Class.APEXTestMethod2.runTests1: line 29, column 24: SOQL query with 0 rows finished in 18 ms
[sf:deploy] 20081201225633.282:Class.APEXTestMethod2.runTests1: line 29, column 10: ()
[sf:deploy] 20081201225633.282:Class.APEXTestMethod2: line 3, column 35:     returning from end of method public static testMethod void runTests1() in 297 ms
[sf:deploy]
[sf:deploy] Cumulative resource usage:
[sf:deploy]
[sf:deploy] Resource usage for namespace: (default)
[sf:deploy] Number of SOQL queries: 5 out of 100
[sf:deploy] Number of query rows: 2 out of 500
[sf:deploy] Number of SOSL queries: 0 out of 20
[sf:deploy] Number of DML statements: 2 out of 100
[sf:deploy] Number of DML rows: 2 out of 500
[sf:deploy] Number of script statements: 16 out of 200000
[sf:deploy] Maximum heap size: 0 out of 500000
[sf:deploy] Number of callouts: 0 out of 10
[sf:deploy] Number of Email Invocations: 0 out of 10
[sf:deploy] Number of fields describes: 0 out of 10
[sf:deploy] Number of record type describes: 0 out of 10
[sf:deploy] Number of child relationships describes: 0 out of 10
[sf:deploy] Number of picklist describes: 0 out of 10
[sf:deploy] Number of future calls: 0 out of 10
[sf:deploy] Number of find similar calls: 0 out of 10
[sf:deploy] Number of System.runAs() invocations: 0 out of 20
[sf:deploy]
[sf:deploy] Total email recipients queued to be sent : 0
[sf:deploy] *** Ending Test APEXTestMethod2.public static testMethod void runTests1()
[sf:deploy]




[sf:deploy] *** Beginning Test 4: APEXTestMethod2.public static testMethod void runTests2()
[sf:deploy]
[sf:deploy] 20081201225633.582:Class.APEXTestMethod2.runTests2: line 37, column 13: Insert: SOBJECT:Program__c
[sf:deploy] 20081201225633.582:Class.APEXTestMethod2.runTests2: line 37, column 13:     DML Operation executed in 109 ms
[sf:deploy] 20081201225633.582:Class.APEXTestMethod2.runTests2: line 39, column 10: APEXTestMethod2 Test2_A Lookup By ID
[sf:deploy] 20081201225633.582:Class.APEXTestMethod2.runTests2: line 40, column 24: SOQL query with 1 row finished in 15 ms
[sf:deploy] 20081201225633.582:Class.APEXTestMethod2.runTests2: line 40, column 10: (Program__c:{Zone__c=APEXTestMethod2_Test2_A, Id=a0H30000000ikWtEAI})
[sf:deploy] 20081201225633.582:Class.APEXTestMethod2.runTests2: line 42, column 10: APEXTestMethod2 Test2_A Lookup By Custom Field
[sf:deploy] 20081201225633.582:Class.APEXTestMethod2.runTests2: line 43, column 24: SOQL query with 0 rows finished in 15 ms
[sf:deploy] 20081201225633.582:Class.APEXTestMethod2.runTests2: line 43, column 10: ()
[sf:deploy] 20081201225633.582:Class.APEXTestMethod2.runTests2: line 47, column 13: Insert: SOBJECT:Program__c
[sf:deploy] 20081201225633.582:Class.APEXTestMethod2.runTests2: line 47, column 13:     DML Operation executed in 104 ms
[sf:deploy] 20081201225633.582:Class.APEXTestMethod2.runTests2: line 49, column 10: APEXTestMethod2 Test2_B Lookup By Id
[sf:deploy] 20081201225633.582:Class.APEXTestMethod2.runTests2: line 50, column 24: SOQL query with 1 row finished in 13 ms
[sf:deploy] 20081201225633.582:Class.APEXTestMethod2.runTests2: line 50, column 10: (Program__c:{Zone__c=APEXTestMethod2_Test2_B, Id=a0H30000000ikWuEAI})
[sf:deploy] 20081201225633.582:Class.APEXTestMethod2.runTests2: line 52, column 10: APEXTestMethod2 Test2_B Lookup By Custom Field
[sf:deploy] 20081201225633.582:Class.APEXTestMethod2.runTests2: line 53, column 24: SOQL query with 0 rows finished in 15 ms
[sf:deploy] 20081201225633.582:Class.APEXTestMethod2.runTests2: line 53, column 10: ()
[sf:deploy]
[sf:deploy] Class.APEXTestMethod2.runTests2: line 55, column 9
[sf:deploy]
[sf:deploy]
[sf:deploy] Cumulative resource usage:
[sf:deploy]
[sf:deploy] Resource usage for namespace: (default)
[sf:deploy] Number of SOQL queries: 4 out of 100
[sf:deploy] Number of query rows: 2 out of 500
[sf:deploy] Number of SOSL queries: 0 out of 20
[sf:deploy] Number of DML statements: 2 out of 100
[sf:deploy] Number of DML rows: 2 out of 500
[sf:deploy] Number of script statements: 15 out of 200000
[sf:deploy] Maximum heap size: 0 out of 500000
[sf:deploy] Number of callouts: 0 out of 10
[sf:deploy] Number of Email Invocations: 0 out of 10
[sf:deploy] Number of fields describes: 0 out of 10
[sf:deploy] Number of record type describes: 0 out of 10
[sf:deploy] Number of child relationships describes: 0 out of 10
[sf:deploy] Number of picklist describes: 0 out of 10
[sf:deploy] Number of future calls: 0 out of 10
[sf:deploy] Number of find similar calls: 0 out of 10
[sf:deploy] Number of System.runAs() invocations: 0 out of 20
[sf:deploy]
[sf:deploy] Total email recipients queued to be sent : 0
[sf:deploy] Stack frame variables and sizes:
[sf:deploy]   Frame0
[sf:deploy]
[sf:deploy] *** Ending Test APEXTestMethod2.public static testMethod void runTests2()
[sf:deploy]


Message Edited by sduda on 12-01-2008 03:25 PM

Message Edited by sduda on 12-01-2008 03:28 PM

Message Edited by sduda on 12-01-2008 04:15 PM

Message Edited by sduda on 12-01-2008 04:26 PM
jrotensteinjrotenstein
Could you please provide details of the class or Trigger that you are testing?

Or is your code merely to show the problem you are currently having with a PickList field?
sdudasduda
Yes, the code above demonstrates the problem we are having with picklist fields.
jrotensteinjrotenstein
I have managed to reproduce your error and agree that it appears to be a strange behaviour in Force.com.

It also appears to be related to the order in which some code is executed.

First, I created a custom object (Program__c) with one custom Picklist field (Zone__c).

This test code then generated an error:
Code:
public class ProgramTest {

public static testMethod void ZoneTest() {

Program__c p1 = new Program__c(Zone__c = 'Test 1');
insert p1;

Program__c[] p1test = [SELECT p.Id, p.Zone__c FROM Program__c p WHERE Zone__c = 'Test 1'];
System.AssertEquals(1, p1test.size());

Program__c p2 = new Program__c(Zone__c = 'Test 2');
insert p2;

Program__c[] p2test = [SELECT p.Id, p.Zone__c FROM Program__c p WHERE Zone__c = 'Test 2'];
System.AssertEquals(1, p2test.size()); //This Assert fails because 0 rows were returned
} }

 
Interestingly, I then changed the order of the lines, creating the two test objects before performing the tests:
Code:
public class ProgramTest {

public static testMethod void ZoneTest() {

Program__c p1 = new Program__c(Zone__c = 'Test 1');
insert p1;

Program__c p2 = new Program__c(Zone__c = 'Test 2');
insert p2;

Program__c[] p1test = [SELECT p.Id, p.Zone__c FROM Program__c p WHERE Zone__c = 'Test 1'];
System.AssertEquals(1, p1test.size());

Program__c[] p2test = [SELECT p.Id, p.Zone__c FROM Program__c p WHERE Zone__c = 'Test 2'];
System.AssertEquals(1, p2test.size()); // No Error
}
}

 In this second case, the error did not occur. Thus, it would appear that the second insert is related to the problem.

I then decided to try this with a standard object:
Code:
public class ProgramTest {

public static testMethod void ZoneTest() {

Account a1 = new Account(Name = '1', Type = 'Test 1');
insert a1;

Account[] a1test = [SELECT Id, Type FROM Account WHERE Type = 'Test 1'];
System.AssertEquals(1, a1test.size());

Account a2 = new Account(Name = '2', Type = 'Test 2');
insert a2;

Account[] a2test = [SELECT Id, Type FROM Account WHERE Type = 'Test 2'];
System.AssertEquals(1, a2test.size()); // Same error - no rows returned } }

 Yet, it works fine when the rows are rearranged:

Code:
public class ProgramTest {

public static testMethod void ZoneTest() {

Account a1 = new Account(Name = '1', Type = 'Test 1');
insert a1;

Account a2 = new Account(Name = '2', Type = 'Test 2');
insert a2;

Account[] a1test = [SELECT Id, Type FROM Account WHERE Type = 'Test 1'];
System.AssertEquals(1, a1test.size());

Account[] a2test = [SELECT Id, Type FROM Account WHERE Type = 'Test 2'];
System.AssertEquals(1, a2test.size()); // No Error } }

I would have to agree that it looks like a bug in the Force.com system.