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
sandeepathadusandeepathadu 

hi help with test case

sandeepathadusandeepathadu
this is the trigger i have wriiten 
trigger caseAssignWebCaseToAccountOwner on Case (before update) {
for(case c :trigger.new){
ID profile = [select id from Profile where name = 'System Administrator'].id; 
user u = [Select id,name,IsActive from user where ProfileId =: profile limit 1 ];
if(c.Origin == 'Portal' && c.SSP_owner_Update__c==false && c.accountid!=null && u.isactive == True){
 account a = [select id,name,OwnerId from account where id=:c.accountid];
 c.ownerid=a.ownerID;
 c.SSP_owner_Update__c=true;
}
 else if(c.Origin == 'Portal' && u.isactive == false )
 c.ownerid='005Q0000000f95r';

}
}
the test case i have wriiten getting 87 percent not covering the else part plz help
@istest
private class UpdateTicketOwner_Test
{
static testMethod void MytestClass()
{

  Account a1 = new Account();
  a1.Name='SriRam';
  a1.CurrencyIsoCode='INR';
  a1.Primary_Contact_s_Email__c='SriRam@Y-Axis.com';
  
  insert a1;



  Case c1 = new Case();
  c1.Accountid=a1.id;
  c1.CurrencyIsoCode='INR';
  c1.Status='New';
  c1.Origin='Portal';
  c1.Priority='Medium';
  c1.SSP_owner_Update__c=false;
  
  insert c1;
 

 update c1;
    
  if((c1.Origin == 'Portal')&&(c1.SSP_owner_Update__c==false)&&(c1.accountid!=null))
  {
   c1.ownerid=a1.ownerID;
    c1.SSP_owner_Update__c=true;
  }
  
 }
 
 
 
}
plz help

 

 

Shashikant SharmaShashikant Sharma

 

Here is your test class

 

@istest
private class UpdateTicketOwner_Test
{
static testMethod void MytestClassForActive()
{
  Profile p = [select id from profile where name='System Administrator'];

  User testUser = new User(alias = 'standt', email='systemadminuser@testContect.com',
            emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US',
            localesidkey='en_US', profileid = p.Id,
            timezonesidkey='America/Los_Angeles', username='systemadminuser@testContect.com');
            
  insert testUser;
  Test.startTest();
  Account a1 = new Account();
  a1.Name='SriRam';
  a1.CurrencyIsoCode='INR';
  a1.Primary_Contact_s_Email__c='SriRam@Y-Axis.com';
  
  insert a1;



  Case c1 = new Case();
  c1.Accountid=a1.id;
  c1.CurrencyIsoCode='INR';
  c1.Status='New';
  c1.Origin='Portal';
  c1.Priority='Medium';
  c1.SSP_owner_Update__c=false;
  
  insert c1;
  update c1;
  Test.stopTest();    
  
  
 }
 
static testMethod void MytestClassForInActive()
{
  Profile p = [select id from profile where name='System Administrator'];

  User testUser = new User(alias = 'standt', email='systemadminuser@testContect.com',
            emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US',
            localesidkey='en_US', profileid = p.Id,
            timezonesidkey='America/Los_Angeles', username='systemadminuser@testContect.com' , isActive = false);
            
  insert testUser;
  Test.startTest();
  Account a1 = new Account();
  a1.Name='SriRam';
  a1.CurrencyIsoCode='INR';
  a1.Primary_Contact_s_Email__c='SriRam@Y-Axis.com';
  
  insert a1;



  Case c1 = new Case();
  c1.Accountid=a1.id;
  c1.CurrencyIsoCode='INR';
  c1.Status='New';
  c1.Origin='Portal';
  c1.Priority='Medium';
  c1.SSP_owner_Update__c=false;
  
  insert c1;
 

 update c1;
    
 Test.stopTest(); 
  
 } 
 
}

 let me know if any issues in it.