You need to sign in to do that
Don't have an account?
Kevin Chiles 930
Not enough coverage on Trigger for Record Type
Hello!
I am having an error where I do not have enough coverage on my trigger to deploy. My code covers the whole trigger except the crucial record type update. Any help is greatly appreciated!
Trigger:
trigger PartnerContractRecordtype on Case (before update) {
for (Case c : Trigger.New) {
Partner_Contract__c pc =[Select Id ,RecordTypeId from Partner_Contract__c where id=:c.Partner_Contract__c limit 1];
RecordType rt = [select id from Recordtype where SobjectType='Partner_Contract__c' and Name =:'Approval'];
if (c.Status =='Partner - Pending Paperwork' && c.Partner_Contract__c!=Null){
pc.RecordtypeId=rt.id;
update pc;
}
}
}
Class:
@isTest(SeeAllData = true)
public class PartnerContractTrigger
{
public static testMethod void PartnerContractTrigger()
{
Account a = New Account(Name='test',recordtypeId=[Select Name, Id From RecordType
Where sObjectType='Account' and isActive=true and Name='Affiliate'].id);
insert a;
Contact ct=New Contact(FirstName='sarah',LastName='jenny',email='test@test.com',AccountId=a.id);
insert ct;
Account mpdefault = New Account(Name='Megapath - Default',recordtypeId=[Select Name, Id From RecordType
Where sObjectType='Account' and isActive=true and Name='Affiliate'].id);
Contact ct2=New Contact(FirstName='sarah',LastName='jenny',email='test@test.com',AccountId=mpdefault.id);
insert ct2;
Insert mpdefault;
Partner_Contract__c pc = New Partner_Contract__c(Name='0',Parent_Partner__c=mpdefault.id,Status__c='Active',
PartnerProgram__c='Referral',Partner__c=a.Id,recordtypeId=[Select Name, Id From RecordType
Where sObjectType='Partner_Contract__c' and isActive=true and Name='Non Approval'].id
);
Insert pc;
Availiable_Contract__c ac = New Availiable_Contract__c(Name='0',Contract_Rank__c=1,Partner__c=a.Id,Partner_Contract__c=pc.Id
);
Insert ac;
RecordType recordtypeId2=[Select Name, Id From RecordType
Where sObjectType='Partner_Contract__c' and isActive=true and Name='Approval'];
Case C= new Case(AccountId=a.id,ContactId=ct.Id,Sales_Rep__c=UserInfo.getUserId(),Case_Request_Type__c='Partner Onboarding',
recordtypeId=[Select Name, Id From RecordType
Where sObjectType='Case' and isActive=true and Name='Channel Support'].id,Partner_Contract__c=pc.id,Company_Name__c=a.Name,
Clarity_Account_ID__c='N/A',Site_Contact__c='Test', Site_Contact_Phone__c='3157775695',Primary_Affiliate__c='Megapath - Default',
Primary_Affiliate_ID_2__c='1980',Subject='Onboarding Request for New Partner',Description='Onboarding Request for New Partner');
insert c;
c.Status='Pending Partner Paperwork';
update c;
Pc.Name='1234';
pc.Status__c='Active';
Pc.Partner_Contract_Status__c='Partner Activated';
// pc.recordtypeId=[Select Name, Id From RecordType
// Where sObjectType='Partner_Contract__c' and isActive=true and Name='Approval'].id;
update pc;
}
}
I am having an error where I do not have enough coverage on my trigger to deploy. My code covers the whole trigger except the crucial record type update. Any help is greatly appreciated!
Trigger:
trigger PartnerContractRecordtype on Case (before update) {
for (Case c : Trigger.New) {
Partner_Contract__c pc =[Select Id ,RecordTypeId from Partner_Contract__c where id=:c.Partner_Contract__c limit 1];
RecordType rt = [select id from Recordtype where SobjectType='Partner_Contract__c' and Name =:'Approval'];
if (c.Status =='Partner - Pending Paperwork' && c.Partner_Contract__c!=Null){
pc.RecordtypeId=rt.id;
update pc;
}
}
}
Class:
@isTest(SeeAllData = true)
public class PartnerContractTrigger
{
public static testMethod void PartnerContractTrigger()
{
Account a = New Account(Name='test',recordtypeId=[Select Name, Id From RecordType
Where sObjectType='Account' and isActive=true and Name='Affiliate'].id);
insert a;
Contact ct=New Contact(FirstName='sarah',LastName='jenny',email='test@test.com',AccountId=a.id);
insert ct;
Account mpdefault = New Account(Name='Megapath - Default',recordtypeId=[Select Name, Id From RecordType
Where sObjectType='Account' and isActive=true and Name='Affiliate'].id);
Contact ct2=New Contact(FirstName='sarah',LastName='jenny',email='test@test.com',AccountId=mpdefault.id);
insert ct2;
Insert mpdefault;
Partner_Contract__c pc = New Partner_Contract__c(Name='0',Parent_Partner__c=mpdefault.id,Status__c='Active',
PartnerProgram__c='Referral',Partner__c=a.Id,recordtypeId=[Select Name, Id From RecordType
Where sObjectType='Partner_Contract__c' and isActive=true and Name='Non Approval'].id
);
Insert pc;
Availiable_Contract__c ac = New Availiable_Contract__c(Name='0',Contract_Rank__c=1,Partner__c=a.Id,Partner_Contract__c=pc.Id
);
Insert ac;
RecordType recordtypeId2=[Select Name, Id From RecordType
Where sObjectType='Partner_Contract__c' and isActive=true and Name='Approval'];
Case C= new Case(AccountId=a.id,ContactId=ct.Id,Sales_Rep__c=UserInfo.getUserId(),Case_Request_Type__c='Partner Onboarding',
recordtypeId=[Select Name, Id From RecordType
Where sObjectType='Case' and isActive=true and Name='Channel Support'].id,Partner_Contract__c=pc.id,Company_Name__c=a.Name,
Clarity_Account_ID__c='N/A',Site_Contact__c='Test', Site_Contact_Phone__c='3157775695',Primary_Affiliate__c='Megapath - Default',
Primary_Affiliate_ID_2__c='1980',Subject='Onboarding Request for New Partner',Description='Onboarding Request for New Partner');
insert c;
c.Status='Pending Partner Paperwork';
update c;
Pc.Name='1234';
pc.Status__c='Active';
Pc.Partner_Contract_Status__c='Partner Activated';
// pc.recordtypeId=[Select Name, Id From RecordType
// Where sObjectType='Partner_Contract__c' and isActive=true and Name='Approval'].id;
update pc;
}
}
I've taken the liberty of updating your trigger to make it bulk ready as well are reducing the number of SOQL queries you have to make. You may want to think about updating the if criteria (line 12-14) to first get the old value and compare it to the new value and only change your record type if the status has changed.
NOTE: This code has not been tested and may contain typographical or logical errors
I would also recommend that you look into creating a factory to create your test data for you.
All Answers
NOTE: When including code please use the "Add a code sample" button (icon <>) to increase readability and make referencing code easier.
I've taken the liberty of updating your trigger to make it bulk ready as well are reducing the number of SOQL queries you have to make. You may want to think about updating the if criteria (line 12-14) to first get the old value and compare it to the new value and only change your record type if the status has changed.
NOTE: This code has not been tested and may contain typographical or logical errors
I would also recommend that you look into creating a factory to create your test data for you.
I would recommend that you create a utility class that contains statics for these types of things. For example:
Then use that in your test classes and your triggers. This will keep you from making a typo since the class will not deploy / save if you don't have the variable name set correctly.
By adding lines 12 and 15 we don't try to re assign the record type if the status was already set and we just happened to update something else on the object.