1

I'm working in the developer council, and my code coverage stops at line 19 for no apparent reason (c.RecordType=rtO;). I would like to upload my code. It's a bit messy, but it's working perfectly well.

Class:

public class ControllerEscrowLoanConvertView {
    public Id escId;
    public String convertedId;
            public Id propTId;

    public ControllerEscrowLoanConvertView(ApexPages.StandardController stdController){
        escId = ApexPages.CurrentPage().getParameters().get('id');

    }


    public PageReference convert(){


        Escrow__c l = [SELECT Id, name, Primary_Contact__c, Property_id__c, Owner_Name__c, Commission__c, Already_Converted__c, Contract_Price__c, Project_Close__c, Property__c, Sale_Price__c, Asking_Price__c, Down_Payment__c, Mortgage_Amount__c, Occupancy_at_Close__c, Transaction_Notes__c, Close_Date__c, CAP_Rate__c, Sale_Price_SF__c, Lease_Expiration_Date__c, Term_Remaining_At_Close__c, Date_Reported__c, Loan_Amount__c, Loan_Type__c, LTV__c, Lender__c, Interest_Rate__c, Lender_Type__c, Amortization__c, Recourse__c, Current_Interest_Rate__c, Payment__c, Prepayment__c FROM Escrow__c WHERE Id=:escId LIMIT 1];
        RecordType rtO = [select id,name from RecordType where name='Loan' and SObjectType='Sales_Comp__c' limit 1];
        if (l.Already_Converted__c  =='Not Converted'||l.Already_Converted__c==NULL){
Sales_Comp__c c=new Sales_Comp__c(Name=l.Name, Owner_Name__c=l.Owner_Name__c, Commission__c=l.Commission__c, Property__c=l.Property__c, Sale_Price__c=l.Contract_Price__c, Asking_Price__c=l.Asking_Price__c, Down_Payment__c=l.Down_Payment__c, Mortgage_Amount__c=l.Mortgage_Amount__c,Occupancy_at_Close__c=l.Occupancy_at_Close__c, Transaction_Notes__c=l.Transaction_Notes__c, Close_Date__c=l.Project_Close__c, CAP_Rate__c=l.CAP_Rate__c, Sale_Price_SF__c=l.Sale_Price_SF__c, Lease_Expiration_Date__c=l.Lease_Expiration_Date__c, Term_Remaining_At_Close__c=l.Term_Remaining_At_Close__c, Deal_Type__c='Loan Close', Date_Reported__c=l.Date_Reported__c, Loan_Amount__c=l.Loan_Amount__c, Loan_Type__c=l.Loan_Type__c, LTV__c=l.LTV__c, Lender__c=l.Lender__r.id, Interest_Rate__c=l.Interest_Rate__c, Lender_Type__c=l.Lender_Type__c, Amortization__c=l.Amortization__c, Recourse__c=l.Recourse__c, Current_Interest_Rate__c=l.Current_Interest_Rate__c, Payment__c=l.Payment__c, Prepayment__c=l.Prepayment__c);
        c.RecordType=rtO;

insert c;
        l.Already_Converted__c='Converted';
       update l;
        convertedId = c.Id;

        String cID=l.Primary_Contact__c;



            //update assoc. Propety Status
        if(l.Property__c != null)
        {
        propTId=l.Property_id__c;


        Property__c property=[SELECT Id, name, Primary_Contact__c, Sales_Status__c, Date_Reported__c, Loan_Amount__c, Loan_Type_bcc__c, LTV__c, Lender__c, Interest_Rate__c, Lender_Type__c, Amortization__c, Recourse__c, Current_Interest_Rate__c, Payment__c, Prepayment__c FROM Property__c WHERE Id=:propTId LIMIT 1];
        property.Sales_Status__c='Sales Comp';
        property.Date_Reported__c=l.Date_Reported__c; property.Loan_Amount__c=l.Loan_Amount__c; property.Loan_Type_bcc__c=l.Loan_Type__c; property.LTV__c=l.LTV__c; property.Lender_lu__c=l.Lender__c; property.Interest_Rate__c=l.Interest_Rate__c; property.Lender_Type__c=l.Lender_Type__c; property.Amortization__c=l.Amortization__c; property.Recourse__c=l.Recourse__c; property.Current_Interest_Rate__c=l.Current_Interest_Rate__c; property.Payment__c=l.Payment__c; property.Prepayment__c=l.Prepayment__c;
        update property;
}

//transfer all commissions
List<Commission__c> coms=[SELECT Id, Escrow__c, Sales_Comp__c FROM Commission__c WHERE Escrow__c=:l.id];

        if(coms.size()>0){
        for(Commission__c i: coms)
        {
        i.Sales_Comp__c=c.id;
        update i;
}
}
                            //update contact stage
        List<Contact> contacts=[SELECT Id, Sales_Status__c FROM Contact WHERE id=:cID];

        if(contacts.size()>0){
        for(Contact i: contacts)
        {
                if(i.Sales_Status__c=='Escrow'||i.Sales_Status__c=='Listing'||i.Sales_Status__c=='Proposal'||i.Sales_Status__c=='Unconfirmed'||i.Sales_Status__c==NULL)
        {
        i.Sales_Status__c='Sales Comp';
        update i;
        }

}
}  
        }

        else{
                String sServerName = ApexPages.currentPage().getHeaders().get('Host');
        sServerName = 'https://'+sServerName+'/';
        PageReference retPage = new PageReference(sServerName + '/apex/EscrowLoanConvertView2?id='+ escId); 
        retPage.setRedirect(true);
        System.Debug('#######ALREADYCONVERTED' );

        return retPage;
        }



        String sServerName = ApexPages.currentPage().getHeaders().get('Host');
        sServerName = 'https://'+sServerName+'/';
        PageReference retPage = new PageReference(sServerName + convertedId); 
        retPage.setRedirect(true);


        return retPage;
    } 
    public PageReference back(){
            String sServerName = ApexPages.currentPage().getHeaders().get('Host');
        sServerName = 'https://'+sServerName+'/';
        PageReference retPage = new PageReference(sServerName + escId); 
        retPage.setRedirect(true);

        return retPage;
    }      
}

Test Class:

@isTest
public class ControllerEscrowLoanConvertViewTest
{

    static testMethod void convert()

    {   Id propTId;


Contact c=new Contact(lastname='lastname',Sales_Status__c='Escrow');
        insert c;

        Property__c pro = new Property__c(Primary_Contact__c=c.id);
        insert pro;


        Escrow__c l = new Escrow__c (
        Name = 'Test Name',
        Already_Converted__c = 'Not Converted',
        Property__c = pro.id,
        Sale_Price__c = 8888888888.00,
        Asking_Price__c = 1777777777,
        Down_Payment__c = 55555555,
        Mortgage_Amount__c = 444444,
        Occupancy_at_Close__c = 333,
        Transaction_Notes__c = 'TEST TEST',
            Buyer_lu__c=c.id,
        Close_Date__c = date.Today(),
        Sale_Price_SF__c = 25,
        Term_Remaining_At_Close__c = 17.00,
        Lease_Expiration_Date__c = date.Today());
        insert l;
system.assertNotEquals(l.Property__c, NULL) ;       



        propTId=l.Property_id__c;



        system.assertNotEquals(l.Property__c, NULL);

        Sales_Comp__c sc=new Sales_Comp__c(Name=l.Name, Owner_Name__c=l.Owner_Name__c, Commission__c=l.Commission__c, Property__c=l.Property__c, Sale_Price__c=l.Contract_Price__c, Asking_Price__c=l.Asking_Price__c, Down_Payment__c=l.Down_Payment__c, Mortgage_Amount__c=l.Mortgage_Amount__c,Occupancy_at_Close__c=l.Occupancy_at_Close__c, Transaction_Notes__c=l.Transaction_Notes__c, Close_Date__c=l.Project_Close__c, CAP_Rate__c=l.CAP_Rate__c, Sale_Price_SF__c=l.Sale_Price_SF__c, Lease_Expiration_Date__c=l.Lease_Expiration_Date__c, Term_Remaining_At_Close__c=l.Term_Remaining_At_Close__c, Deal_Type__c='Loan Close', Date_Reported__c=l.Date_Reported__c, Loan_Amount__c=l.Loan_Amount__c, Loan_Type__c=l.Loan_Type__c, LTV__c=l.LTV__c, Lender__c=l.Lender__c, Interest_Rate__c=l.Interest_Rate__c, Lender_Type__c=l.Lender_Type__c, Amortization__c=l.Amortization__c, Recourse__c=l.Recourse__c, Current_Interest_Rate__c=l.Current_Interest_Rate__c, Payment__c=l.Payment__c, Prepayment__c=l.Prepayment__c);
                  RecordType rtO = [select id,name from RecordType where name='Loan' and SObjectType='Sales_Comp__c' limit 1];
        sc.RecordType=rtO;   
     insert sc;

        Id bId=l.Buyer_lu__c;

        String cID=l.Primary_Contact__c;

              MRG_Ownership__c own= new MRG_Ownership__c(Primary_Contact__c=true,Contact__c=bId,property__c=l.Property__c,Contact_Role__c='Owner');
insert own;

                Commission__c com=new Commission__c();
        com.Sales_Comp__c=sc.id;
        com.Escrow__c=l.id;
        insert com;



            PageReference pageRef = Page.EscrowConvertView;
            Test.setCurrentPage(pageRef);
            ApexPages.currentPage().getParameters().put('id',l.Id);
            ApexPages.StandardController std = new ApexPages.StandardController(new Escrow__c());
            ControllerEscrowLoanConvertView cont = new ControllerEscrowLoanConvertView (std);
            cont.convert();
            cont.back();
    }
    static testMethod void converttwo()
    {
            Property__c pro = new Property__c();
            insert pro;

            Escrow__c l1 = new Escrow__c (
Name = 'Test Name',
        Already_Converted__c = 'Converted',
        Property__c = pro.id,
        Sale_Price__c = 8888888888.00,
        Asking_Price__c = 1777777777,
        Down_Payment__c = 55555555,
        Mortgage_Amount__c = 444444,
        Occupancy_at_Close__c = 333,
        Transaction_Notes__c = 'TEST TEST',
        Close_Date__c = date.Today(),
        Sale_Price_SF__c = 25,
        Term_Remaining_At_Close__c = 17.00,
        Lease_Expiration_Date__c = date.Today());

            insert l1;

            PageReference pageRef = Page.EscrowConvertView;
            Test.setCurrentPage(pageRef);
            ApexPages.currentPage().getParameters().put('id',l1.Id);
            ApexPages.StandardController std = new ApexPages.StandardController(new Escrow__c());
            ControllerEscrowLoanConvertView cont = new ControllerEscrowLoanConvertView (std);
            cont.convert();
            cont.back();

    }

}
11
  • 1
    Wrapping your entire method in try { /*do everything*/ } catch (Exception pokemon) { system.debug(pokemon); } is really bad practice, as you have just discovered. This messy pattern is the exact reason your dropoff is "for no apparent reason."
    – Adrian Larson
    Feb 22, 2016 at 23:38
  • I took out try/catch, which was not really necessary to have in there anymore anyways. However, this did not increase my code coverage
    – MRG
    Feb 22, 2016 at 23:42
  • But probably resulted in the test failing for a NullPointerException?
    – Adrian Larson
    Feb 22, 2016 at 23:42
  • No. The test passed. This code has been modified and expanded several times. The try/catch was leftover from an earlier version, when the method was much smaller. I took it out, but the code coverage is basically exactly the same percentage.
    – MRG
    Feb 22, 2016 at 23:44
  • 2
    Line 19 should most likely be c.RecordTypeId = rtO.Id; You're currently using an object reference rather than the id of that related RecordType. It's also probably throwing or logging an exception that I speculate you're catching and ignoring.
    – Mark Pond
    Feb 23, 2016 at 0:04

1 Answer 1

4

It seems like your test is actually failing to progress beyond that line. Add a system.assert(false) on the following line, it will likely illuminate you.

Not the answer you're looking for? Browse other questions tagged or ask your own question.