1

I create multiple (x5) classes in my Trigger like this :

class TypeHandler_XX implements TypeHandler {
public void action(Task record) {
             /* Block code */
        }
}

In the code that I am testing the value of my RecordType and I call the appropriate class.

My problem is this : How can I test the other class, in my ClassTest. Code coverage = 67%

Thanks

1 Answer 1

2

When you insert your test records in your test code you need to assign the appropriate Record Type to the record. I assume it's working presently due to the default Record Type being assigned. You can discover the Id's of the Record Types for an object using Apex Describe then assign the Id to the RecordTypeId field (see the section below this topic for further discussion).

Schema.DescribeSObjectResult accountDescribe = Account.SObjectType.getDescribe();
Map<String, Schema.RecordTypeInfo> recordTypesByName = accountDescribe.getRecordTypeInfosByName();

Account newAccount = new Account();
newAccount.RecordTypeId = recordTypesByName.get('Record Type X1').getRecordTypeId();
3
  • 1
    I made ​​the recovery of the value of RecordType in my Trigger and not in the class test. But your answer helped me a lot, I learned more about the Apex language. Thank you very much. Jan 7, 2014 at 12:41
  • 1
    I did it ! Code Coverage 100%. Thank you again Jan 7, 2014 at 13:54
  • Excellent always a good feeling! Of course you have lots of asserts as well! ;-) Jan 7, 2014 at 14:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .