function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
k practicek practice 

How to write testclass for below Trigger?

Hi,
      trigger autoCreatOpp on Case (after insert, after update)
{
list<Opportunity> getOpp = new list<Opportunity>();
list<Opportunity> newOpp = new list<Opportunity>();

set<id> caseid = new set<id>();
for(Case newCase : Trigger.new)
{
if(newcase.status == 'Escalated')
caseid.add(newCase.id);
}

getOpp = [select id,recordtypeid,Orginating_Case__c  from Opportunity where recordtype.name='Professional_Service_Change_Order' and Orginating_Case__c =: caseid ];

for(Case c : [select id,status,casenumber,accountid,subject from case where id =: caseid ])
{
if(getOpp.size() == 0)
{
Opportunity opp = new Opportunity();
opp.name = c.accountid +'-'+ c.subject;
opp.accountid = c.accountid;
opp.recordtypeid='012j0000000WH2U';
opp.closedate = system.today()+30;
opp.stagename = 'Open';
opp.Orginating_Case__c = c.casenumber;
newOpp.add(opp);
}
}
insert newOpp;
}

help me...
Sri549Sri549
Hello K,

Please use this Code for above Trigger.

@IsTest(Seealldata=True)
Public Class Test_autoCreatOpp
{
    Public Static testmethod void autoCreatOpp()
    {
        Case cs = new Case();
        cs.status = 'Escalated';
        Insert cs;        
    }
}

Please mark this as a Best Answer for futhur benefits.
or Reply me for any more doubts.

Many Regards
Srinivas

 
Iqrar AhmedIqrar Ahmed
Hi k,
First you need to create account then assign it with case and also create opportunity and then assign it with case then rely all to your test class
Best Regards:
IQRAR AHMED 
Senior Salesforce/.Net Developer
k practicek practice
Hi AHMED,

Above class Covered only 44%.How to improve code coverage?