+ Start a Discussion
Kanus waveKanus wave 

can any one write test class to the below scenario am tried am getting 74% but i need 90+

public with sharing class LP_CreateNewCasePage_Controller 
{

public String Id;
public Id ParentId;
public id selectedrecordtype;
 public PageReference OtherRedirect(){
   
    try{
           System.debug('Selected RecordType is'+selectedrecordtype);
           Id recTypeId = [SELECT id from RecordType WHERE id=:selectedrecordtype].id;
           PageReference p = new PageReference('/' + Case.SObjectType.getDescribe().getKeyPrefix() + '/e');
           Map<String, String> m = p.getParameters();
   
                if((string)ApexPages.currentPage().getParameters().get('retURL').substring(1,4)!='500')
                {
                ParentId = ApexPages.currentPage().getParameters().get('retURL').substring(1,16);
                Id=(string)ParentId;
                if(Id.Startswith('003')){
                m.putAll(ApexPages.currentPage().getParameters());
                m.put('nooverride', '1');
                m.put('RecordType',recTypeId);                        
                p.setRedirect(true);
                    }
                if(Id.Startswith('001')){
                m.putAll(ApexPages.currentPage().getParameters());
                m.put('nooverride', '1');
                m.put('RecordType',recTypeId);                        
                p.setRedirect(true);               
                    }
                return p;
                }

                else{
                
                m.put('nooverride', '1');
                m.put('RecordType',recTypeId);                        
                p.setRedirect(true);
                return p;

                }
   }
   catch(Exception l_objEx)
        {            
            String l_stMsg = 'Exception while redirecting to Case Creation Page.';
            String l_stErrMessage = l_objEx.getTypeName()+': '+l_stMsg;
            System.debug(l_stErrMessage);
            return null;
        }
   }
   }

Thanks in Advance!
Harish RamachandruniHarish Ramachandruni
Hi,


If Your are providing selectedrecordtype . Dont provide value in test class . it will get and show me your test class if it is possible .



Regards ,
Harish.R.
Kanus waveKanus wave
sorry sir i cant..can you please write the code for this..im getting nervous
 
Harish RamachandruniHarish Ramachandruni
Hi,


Provide me your test class i can help you nothing to worry . other wise i have to create in my account . 



Regards ,
Harish.R.
Kanus waveKanus wave
sir,create a new test class in your Account i think for you hardly it will take 10 -15 mints.plz
 
Swaraj Behera 7Swaraj Behera 7
Hi Kanus,
Can you please share your test class.
Below i tried to make test class of the above class in my devloper org.
I hope it helps.
 
@isTest
 Public class LP_CreateNewCasePage_ControllerTest{

    Static testmethod void unittest1(){
    
      Profile p = [SELECT Id FROM Profile WHERE Name='System Administrator']; 
      User u = new User(Alias = 'standt', Email='standardtestuser@force.com', 
      EmailEncodingKey='UTF-8', LastName='TestUser', LanguageLocaleKey='en_US', 
      LocaleSidKey='en_US', ProfileId = p.Id, 
      TimeZoneSidKey='America/Los_Angeles',    UserName='standardtestuser@force.com');
    
       Account a = new Account();
        a.Name = 'Test Account';
        Insert a;

        Contact cont = New Contact();
        cont.FirstName ='Bob';
        cont.LastName ='Masters';
        cont.AccountId = a.Id;
        Insert cont;
        
    
       Case caseObj = new Case(
      ContactId = cont.id,
      AccountId = a.id,
      Status = 'Working',
      Origin = 'Phone'
    );
   

  System.runAs(u)
   {
    LP_CreateNewCasePage_Controller  LpnewcaseController =new  LP_CreateNewCasePage_Controller();
    LpnewcaseController.Id=a.id;

    LpnewcaseController.selectedrecordtype='01228000000pFqkAAE';
    
   } 

     }

Thanks,
Swaraj Behera