I'm trying to check a custom setting, containing a list of Record Type Ids against the record type id of new opportunities that are being created. I only want the trigger to complete it's calculation, if there is a match.
When I run my test class, I don't have code coverage for the parts of the code which depend on a match having been found between the opportunity Record Type Id and the Id included in the Custom Setting list. So I'm assuming that when the two are being compared, there isn't a match but I can't figure out why there wouldn't be.
List<WEID__c> weids = WEID__c.getall().values();
Set<Id> validRecordTypeIds = new Set<Id>();
//check that Ids listed in custom setting are valid Ids
for (WEID__c weid : weids) {
try {
validRecordTypeIds.add(weid.WEOppId__c);
} catch (System.StringException e) {
System.debug(
System.LoggingLevel.ERROR,
'Invalid record type id ' + weid.WEOppId__c
);
}
}
for (Opportunity opp : Trigger.new) {
if (validRecordTypeIds.contains(opp.Id)) {
if (opp.Annual_Settlement_Value__c > 0 && opp.Interchange_Rate_Revenue_as_a_percentag__c > 0) {
Decimal fsr = opp.Annual_Settlement_Value__c * opp.Interchange_Rate_Revenue_as_a_percentag__c;
opp.FSR_Estimate_on_Contract_Signature__c = fsr;
} else {
opp.Annual_Settlement_Value__c = null;
opp.FSR_Estimate_on_Contract_Signature__c = null;
}
}
}
Part of my test class which specified a Record Type Id (I'm happy to post the rest if necessary, I just wanted to keep this post short) -
static testMethod void testFSR() {
Opportunity opp = new Opportunity();
opp.name = 'Test Opp';
opp.RecordTypeId = '012700000005qif';
opp.StageName = '1) Suspect';
opp.CloseDate = date.newInstance(2045, 01, 01);
//cover Credit Agreement Details Required validation rule
opp.Credit_Limit__c = 100.00;
opp.Date_Credit_Limit_Approved__c = date.newInstance(1901, 01, 01);
opp.Payment_Terms_Days__c = 5;
opp.Billing_Cycle__c = 'Daily';
//cover Revenue Values Required validation rule (and provide values required for calculation)
opp.Annual_Settlement_Value__c = 100.00;
opp.Average_transaction_Value_POS__c = 1.00;
opp.Interchange_Rate_Revenue_as_a_percentag__c = 0.1;
insert opp;
}
I do have another section of the test class that specifies a non-matching Id. My custom setting WEID__c contains the field WEOppID__c and one of the values is 012700000005qif.