You need to sign in to do that
Don't have an account?
testing exception
How can you test a catch exception if it looks to see if a field is set to null.
The trigger is
trigger UpdateEntitlement on Case (before insert,before update, after update) {
Id caseRecordTypeId = [Select id from RecordType where sObjectType = 'Case' and developerName ='Service_Desk' ].id ;
if (trigger.isBefore && trigger.isInsert) {
for (Case c : Trigger.new) {
if (c.RecordTypeID == caseRecordTypeId )
if (c.Entitlement == null) {
try{
//c.EntitlementId = [select Id from Entitlement where Id = '550L0000000Q299IAC'].id;
c.EntitlementId = [Select Id from Entitlement Where AccountId = :c.AccountId and Default_Entitlement__c=True limit 1].id;
}catch(QueryException e) {
System.debug('No records found. Maybe you should set it to Null:' + e);
}
}}
}}
my test class is
trigger UpdateEntitlement on Case (before insert,before update, after update) {
Id caseRecordTypeId = [Select id from RecordType where sObjectType = 'Case' and developerName ='Service_Desk' ].id ;
if (trigger.isBefore && trigger.isInsert) {
for (Case c : Trigger.new) {
if (c.RecordTypeID == caseRecordTypeId )
if (c.Entitlement == null) {
try{
//c.EntitlementId = [select Id from Entitlement where Id = '550L0000000Q299IAC'].id;
c.EntitlementId = [Select Id from Entitlement Where AccountId = :c.AccountId and Default_Entitlement__c=True limit 1].id;
}catch(QueryException e) {
System.debug('No records found. Maybe you should set it to Null:' + e);
}
}}
}}