Test Class for Custom Objects for Versions Older Than 10

Ed Ralph

Last Update 2 jaar geleden

//test class for SuperRoundRobin triggers on custom objects (and standard objects beyond the out-of-the-box Lead, Account, Contact, Opportunity and Case)

//if you are required to put customer specific configuration into this test class, there will be a comment starting '//Config required:' in the preceding line telling you what to do


@isTest

private class SRRTriggerTest {

@isTest

static void testSRRTrigger() {


//Config required: objectType is the API Name for the object you created the trigger on. e.g. My_Custom_Object__c or Campaign. This example is for Campaign.

String objectType = 'Campaign';

//Config required: objectFieldName: select a field from the object that this test will create a MatchRule with. Easiest is to use a String field like Description

String objectFieldName = 'Description';

//Config required: objectFieldValue: the value in the objectFieldName that will cause a positive match. If you set the objectFieldName to 'Description' then put 'DescriptionValue' here.

String objectFieldValue = 'DescriptionValue';


leadassist__MatchGroup__c mg = leadassist.TestDataFactory.setupTestAndReturnMatchGroup(objectType,objectFieldName,objectFieldValue);

Decimal leadcount_before = mg.leadassist__leadcount__c;


//Config required: this line of Apex code creates a new record of the object you created the trigger on. This test example is for the Campaign object. Remember to include any required fields, and the matching field you set above (Description in this example)


Campaign newRecord = new Campaign(Description='DescriptionValue', Name='Example Campaign', Status='Planned', Use_Round_Robin__c='TRUE');

Test.startTest();

insert newRecord;

Test.stopTest();

leadassist__MatchGroup__c mgAfter = [select leadassist__leadcount__c from leadassist__MatchGroup__c where Id = :mg.Id];

Decimal leadcount_after = mgAfter.leadassist__leadcount__c;

System.assert(leadcount_after == leadcount_before+1);

}

}

Was this article helpful?

0 out of 0 liked this article

Still need help? Message Us