+ Start a Discussion
srinu namani 12srinu namani 12 

Can Anyone help me to cover the lines in bold.

This is my Class and you can see the test class I have written for this but covering only 50%.

public class OverrideNewButtonComponentController {
    Public string sObjectType {get; set;}
    Public string keyPrefix {get; set;}
    Public string infoProLabel {get; set;}
    Public string infoProLawonLabel {get; set;}
    
    List<Line_of_Business__c > listInfoProLawson = new List<Line_of_Business__c >();
    public OverrideNewButtonComponentController(String sobjectName, String objPrefix) {
        sObjectType=sobjectName;
        keyPrefix=objPrefix;
    }
    public OverrideNewButtonComponentController(){}

    public PageReference init() {
           
          if (ApexPages.currentPage().getParameters().get('RecordType') == null) {
          Schema.DescribeSObjectResult describeLead = Schema.SObjectType.Lead;
          List<Schema.RecordTypeInfo> rtInfos = describeLead.getRecordTypeInfos();
          for(Schema.RecordTypeInfo rtInfo : rtInfos) {
            if(rtInfo.getName() != 'Master' && rtInfo.isAvailable()) {
            ApexPages.currentPage().getParameters().put('RecordType', rtInfo.getRecordTypeId());
           }
          }
          
         }

        String userLawson = String.Valueof([Select id, Lawson_Division__c from User where id = : Userinfo.getUSerId()].Lawson_Division__c);




        if (userLawson != null) {
            listInfoProLawson = [SELECT Id, Name, Lawson_Division__c, Infopro_Division__r.Name from Line_of_Business__c where Lawson_Division__r.Name = :userLawson];
            system.debug('sObjectType==' + sObjectType);
            if (listInfoProLawson.size() >= 1 && listInfoProLawson.get(0).Name != null && listInfoProLawson.get(0).Infopro_Division__r.Name != null) {
                String labelVal ;
                if(sObjectType=='Opportunity')
                    labelVal = System.Label.OpportunityNewButtonOverRideLabel;
                else if(sObjectType=='Lead')
                    labelVal= System.Label.LeadNewButtonOverRideLabel;
                labelVal = labelVal.trim();
                List<String> labels = labelVal.split(',');
                System.debug('labels==' + labels);
                infoProLawonLabel = labels.get(0).trim();
                infoProLabel = labels.get(1).trim();
                System.debug(sObjectType+'sObjectTypes---');

                //return new PageReference('/setup/ui/recordtypeselect.jsp?ent=' + sObjectType + '&nooverride=1&retURL=%2F'+keyPrefix+'%2Fo&save_new_url=%2F'+keyPrefix+'%2Fe%3FretURL%3D%252F'+keyPrefix+'%252Fo&' + infoProLawonLabel + '=' + listInfoProLawson.get(0).Name + '&' + infoProLawonLabel + '_lkid=' + listInfoProLawson.get(0).Id + '&' + infoProLabel + '=' + listInfoProLawson.get(0).Infopro_Division__r.Name);
                if(sObjectType=='Lead' && (ApexPages.currentPage().getParameters().get('RecordType') == Schema.SObjectType.Lead.getRecordTypeInfosByName().get('Field Sales Lead').getRecordTypeId() || ApexPages.currentPage().getParameters().get('RecordType') == Schema.SObjectType.Lead.getRecordTypeInfosByName().get('Refer Republic Lead').getRecordTypeId())){
                    Pagereference page = new PageReference('/'+keyPrefix+'/e?nooverride=1&retURL=%2F'+keyPrefix+'%2Fo&save_new_url=%2F'+keyPrefix+'%2Fe%3FretURL%3D%252F'+keyPrefix+'%252Fo&' + infoProLawonLabel + '=' + listInfoProLawson.get(0).Name + '&' + infoProLawonLabel + '_lkid=' + listInfoProLawson.get(0).Id + '&' + infoProLabel + '=' + listInfoProLawson.get(0).Infopro_Division__r.Name + '&lea16country=USA');
                    //page.setRedirect(true);
                    return page;
                }
                else if(sObjectType=='Opportunity' && (ApexPages.currentPage().getParameters().get('RecordType') == Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('Field Sales Opportunity').getRecordTypeId())){
                System.debug(sObjectType+'inside sObjectTypes---');
                    Pagereference page = new PageReference('/'+keyPrefix+'/e?nooverride=1&retURL=%2F'+keyPrefix+'%2Fo&save_new_url=%2F'+keyPrefix+'%2Fe%3FretURL%3D%252F'+keyPrefix+'%252Fo&' + infoProLawonLabel + '=' + listInfoProLawson.get(0).Name + '&' + infoProLawonLabel + '_lkid=' + listInfoProLawson.get(0).Id + '&' + infoProLabel + '=' + listInfoProLawson.get(0).Infopro_Division__r.Name);
                    //page.setRedirect(true);
                    return page;
                }
                return new PageReference('/'+keyPrefix+'/e?nooverride=1&retURL=%2F'+keyPrefix+'%2Fo&save_new_url=%2F'+keyPrefix+'%2Fe%3FretURL%3D%252F'+keyPrefix+'%252Fo&' + infoProLawonLabel + '=' + listInfoProLawson.get(0).Name + '&' + infoProLawonLabel + '_lkid=' + listInfoProLawson.get(0).Id + '&' + infoProLabel + '=' + listInfoProLawson.get(0).Infopro_Division__r.Name + '&RecordType='+ApexPages.currentPage().getParameters().get('RecordType'));
            }
        }

            //return new PageReference('/setup/ui/recordtypeselect.jsp?ent=' + sObjectType + '&nooverride=1&retURL=%2F'+keyPrefix+'%2Fo&save_new_url=%2F'+keyPrefix+'%2Fe%3FretURL%3D%252F'+keyPrefix+'%252Fo');
        if(sObjectType=='Lead' && (ApexPages.currentPage().getParameters().get('RecordType') == Schema.SObjectType.Lead.getRecordTypeInfosByName().get('Field Sales Lead').getRecordTypeId() || ApexPages.currentPage().getParameters().get('RecordType') == Schema.SObjectType.Lead.getRecordTypeInfosByName().get('Refer Republic Lead').getRecordTypeId())){
            return new PageReference('/'+keyPrefix+'/e?nooverride=1&retURL=%2F'+keyPrefix+'%2Fo&save_new_url=%2F'+keyPrefix+'%2Fe%3FretURL%3D%252F'+keyPrefix+'%252Fo&lea16country=USA&RecordType='+ApexPages.currentPage().getParameters().get('RecordType'));
        }
        else if(sObjectType=='Opportunity' && (ApexPages.currentPage().getParameters().get('RecordType') == Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('Field Sales Opportunity').getRecordTypeId())){
            return new PageReference('/'+keyPrefix+'/e?nooverride=1&retURL=%2F'+keyPrefix+'%2Fo&save_new_url=%2F'+keyPrefix+'%2Fe%3FretURL%3D%252F'+keyPrefix+'%252Fo');
        }
        else if(sObjectType=='Lead' && (ApexPages.currentPage().getParameters().get('RecordType') == Schema.SObjectType.Lead.getRecordTypeInfosByName().get('Special Waste Leads').getRecordTypeId())){
           return new PageReference('/apex/SPWLead?ent=Lead&RecordType='+ApexPages.currentPage().getParameters().get('RecordType')+'&retURL=SPWLead&save_new_url=00Q/e');
        }    
        return new PageReference('/'+keyPrefix+'/e?nooverride=1&retURL=%2F'+keyPrefix+'%2Fo&save_new_url=%2F'+keyPrefix+'%2Fe%3FretURL%3D%252F'+keyPrefix+'%252Fo&RecordType='+ApexPages.currentPage().getParameters().get('RecordType'));
    }


}




Here is the test class I have written.


@istest private class TestOverrideNewButtonComponentController { Static testmethod void OverrideNewButtonComponentController() { OverrideNewButtonComponentController ride = new OverrideNewButtonComponentController();  ride.init(); OverrideNewButtonComponentController controller = new OverrideNewButtonComponentController();      String sbjname='Lead';       String  sbjprefix='00Q';              List<Line_of_Business__c > lst = new List<Line_of_Business__c >(); Line_of_Business__c  lb1=new Line_of_Business__c(); Lawson_Division__c   ld1 = new Lawson_Division__c(); Infopro_Division__c  id1 = new Infopro_Division__c(); Profile p = [SELECT Id FROM Profile WHERE Name='field sales']; User u = new User(Alias = 'standt1', Email='standarduser1@testorg.com', EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US', LocaleSidKey='en_US', ProfileId = p.Id, TimeZoneSidKey='America/Los_Angeles', UserName='myorg1@testorg.com'); System.runAs(u) { ld1.name = 'test'; insert ld1; id1.name = 'testinfo'; insert id1; lb1.name = 'testLawson'; //lb1.Infopro_Division__c = 'testinfo1'; //lb1.Lawson_Division__c = 'test1'; //insert lb1; } } //user U = new user (  }


Please help me in covering the full class.
varun_vatsavarun_vatsa
Hi, 

Ill be happy to help, but could you please paste code in a formatted manner so that it becomes easy to read?