My trigger and my testMethod uses field description:

Schema.DescribeSObjectResult objectDescribe = Contact.sObjectType.getDescribe();
Map<String,Schema.SObjectField> fieldsMap = objectDescribe.fields.getMap(); 

In the trigger:

i'm inserting all fields in a custom object based on fieldsMap.

in the testMethod

i'm trying to verify that all inserted data (by quering my custom object) correspond to a real field based on fieldsMap.

The problem

fieldsMap.get('isemailbounced') for example returns null in test method (I'm running as an admin)

Test fails

I tried to run this code in Execution Anonymous

    Schema.SObjectType targetType = Schema.getGlobalDescribe().get('Contact');
    Schema.DescribeSObjectResult objectDescribe = targetType.getDescribe();
    Map<String,Schema.SObjectField> fieldsMap = objectDescribe.fields.getMap(); 
    System.debug('fieldsMap: '+ fieldsMap.get('isemailbounced'));
    sObject mySObject = targetType.newSObject();

Anonymous execution was successful.

But if i put that code in a class or another controller i got the Exception (because i used mySObject.get('isemailbounced'))

System.SObjectException: Invalid field isemailbounced for Contact

Any Suggestion?

  • 3
    IsEmailBounced was added in Winter '14 so you will need to make sure that class or controller you are executing the code from is on Winter '14 (API 29) or above. The dev console runs with the latest version so that is why its working there. – BarCotter Sep 24 '14 at 16:03
  • I confirm that i was running my testMethod with an older api version --> Some field were not visible. Thank you for your help :) – Akram G Sep 24 '14 at 16:12
  • @BarCotter, you should post that as an answer. – greenstork Sep 24 '14 at 16:14

IsEmailBounced was added in Winter '14, you will need to make sure that the class or controller that is executing the code is on Winter '14 (API 29) or above. The dev console runs with the latest version so that is why it's working there.

SalesForce don't seem to be doing too well with API versioning recently. There are some known issues, see here and here


Check your API version on your class . The Org's Dev Console upgrades by itself but the classes needs to be updated to the latest API versions . The field "IsEmailBounced" has been added in the latest Winter Release . Hence when running the code in the class , make sure you have the latest API versions for it to compile without errors. Make sure you refresh the schema in case if you are using Force.com plugin in Eclipse .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.