You need to sign in to do that
Don't have an account?
Sunil_sfcd803
Can any one help me in writing test class for my below trigger.
Hi All,
Please help me to write test calss for below trigger.Also it will be helpful if you add basic information as comments for understanding.
trigger UpdateTicketDetails on Ticket_Details__c (before insert,before update) {
if(Trigger.isInsert){
Id ticketRecordType = Schema.SObjectType.Ticket_Details__c.getRecordTypeInfosByName().get('Service').getRecordTypeId();
//list<Ticket_Details__c> ticketList = new list<Ticket_Details__c> ();
for(Ticket_Details__c ticket:Trigger.new){
if(ticket.recordTypeId==ticketRecordType){
ticket.Incident__c=False;
ticket.Ticket_Description__c='Ticket is Service Request';
}else{
ticket.Incident__c=True;
ticket.Ticket_Description__c='Ticket is Incident';
}
//ticketList.add(ticket);
}
// insert ticketList;
}
if(Trigger.isUpdate){
for(Ticket_Details__c ticket:Trigger.new){
String oldStatus= Trigger.oldMap.get(ticket.Id).Ticket_status__c;
If(ticket.Ticket_status__c!=oldStatus){
system.debug('Status has been changed');
ticket.Ticket_Summary__c='Status changed from ' + oldStatus +' to '+ ticket.Ticket_status__c+'.';
}
}
}
}
Please help me to write test calss for below trigger.Also it will be helpful if you add basic information as comments for understanding.
trigger UpdateTicketDetails on Ticket_Details__c (before insert,before update) {
if(Trigger.isInsert){
Id ticketRecordType = Schema.SObjectType.Ticket_Details__c.getRecordTypeInfosByName().get('Service').getRecordTypeId();
//list<Ticket_Details__c> ticketList = new list<Ticket_Details__c> ();
for(Ticket_Details__c ticket:Trigger.new){
if(ticket.recordTypeId==ticketRecordType){
ticket.Incident__c=False;
ticket.Ticket_Description__c='Ticket is Service Request';
}else{
ticket.Incident__c=True;
ticket.Ticket_Description__c='Ticket is Incident';
}
//ticketList.add(ticket);
}
// insert ticketList;
}
if(Trigger.isUpdate){
for(Ticket_Details__c ticket:Trigger.new){
String oldStatus= Trigger.oldMap.get(ticket.Id).Ticket_status__c;
If(ticket.Ticket_status__c!=oldStatus){
system.debug('Status has been changed');
ticket.Ticket_Summary__c='Status changed from ' + oldStatus +' to '+ ticket.Ticket_status__c+'.';
}
}
}
}
Below is the sample test class, I could not give you the exact one since I am not aware about mandatory fields and field api name in your org on given object, you just update my test class and use that.
Update the field API name, picklist field value and record type name to query.
Mark solved if it does help you.
All Answers
Below is the sample test class, I could not give you the exact one since I am not aware about mandatory fields and field api name in your org on given object, you just update my test class and use that.
Update the field API name, picklist field value and record type name to query.
Mark solved if it does help you.
Thanks for your help.With few modifications it was successfull.