You need to sign in to do that
Don't have an account?

test class for the trigger
hi
am not able to cover the test class for this trigger can any one help me how to cover the record types in the test class
below is the my trigger and test class
trigger DuplicateCR on Requirement__c (before insert,before update)
{
String dupErrMsg = 'good';
String stgSkipMsg = 'yyy';
String enquiryStatusInvalid = 'xxxx';
List<Requirement__c> cRObjectList = new List<Requirement__c>();
cRObjectList = [SELECT First_Name__c,Last_Name__c,Phone_Number__c,Email_Id__c
FROM Requirement__c limit 50000];
for(Requirement__c tempCR :trigger.new)
{
for(Requirement__c tempCurCR : cRObjectList)
{
id RT_Client=Schema.SObjectType.Requirement__c.getRecordTypeInfosByName().get('Requirement').getRecordTypeId();
if(System.Trigger.IsInsert && tempCR.RecordTypeId==RT_Client
&& (tempCR.First_Name__c==tempCurCR.First_Name__c &&
tempCR.Last_Name__c == tempCurCR.Last_Name__c)
&& tempCR.Phone_Number__c == tempCurCR.Phone_Number__c &&
tempCR.Email_Id__c == tempCR.Email_Id__c
&& tempCR.Duplicate__c==false)
{
tempCR.addError(dupErrMsg);
}
}
id RT_customer=Schema.SObjectType.Requirement__c.getRecordTypeInfosByName().get('Cus Requirement').getRecordTypeId();
if(tempCR.RecordTypeId==RT_customer && tempCR.Detail__c != NULL)
{
Customer__c newCustObj=[SELECT First_name__c,Last_name__c FROM Customer__c WHERE
Id = :tempCR.Detail__c];
tempCR.First_Name__c=newCustObj.First_name__c;
}
}
}
test class
@IsTest(SeeAllData=true)
public class Test_DuplicateCR
{
public static testmethod void T_DuplicateCR()
{
Requirement__c cr=new Requirement__c();
cr.Salutation__c='Mr';
cr.First_Name__c='test';
cr.Last_Name__c='test1';
cr.Phone_Number__c='9999999999';
cr.Email_Id__c='test@gmail.com';
cr.Min_Area_Sq_Ft__c='500';
cr.Max_Area_Sq_ft__c='600
insert cr;
cr.Min_Area_Sq_Ft__c='600';
cr.Max_Area_Sq_ft__c='700';
update cr;
}
}
Regards
venkatesh
add
cc.RecordTypeId and populate record type value.
Or run as a particular user whose profiles has got default record Type you are looking.
Go thorough this link
http://salesforceworld4u.blogspot.com/b/post-preview?token=_gORyj8BAAA.IGmXF2jnnaYvJtq06L3jcQ._w001bsRMt2CWzQUXW4CGA&postId=9098585906852762316&type=POST
If this post answers your question, please mark it as solution and give kudos for this post
Thanks